home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / gnudc.zip / decimal.h < prev    next >
C/C++ Source or Header  |  1993-04-29  |  3KB  |  94 lines

  1. /* 
  2.  * Header file for decimal.c (arbitrary precision decimal arithmetic)
  3.  *
  4.  * Copyright (C) 1984 Free Software Foundation, Inc.
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2, or (at your option)
  9.  * any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, you can either send email to this
  18.  * program's author (see below) or write to: The Free Software Foundation,
  19.  * Inc.; 675 Mass Ave. Cambridge, MA 02139, USA.
  20.  */
  21.  
  22. /* Autoconf stuff */
  23. #ifndef HAVE_BCOPY
  24. #undef bcopy
  25. #define bcopy(s2, s1, n) memcpy (s1, s2, n)
  26. #endif
  27.  
  28. #ifndef HAVE_BZERO
  29. #undef bzero
  30. #define bzero(b, l) memset (b, 0, l)
  31. #endif
  32.  
  33. /* Define the radix to use by default, and for representing the
  34.    numbers internally.  This does not need to be decimal; that is just
  35.    the default for it.  */
  36.  
  37. /* Currently, this is required to be even for this program to work. */
  38.  
  39. #ifndef RADIX
  40. #define RADIX 10
  41. #endif
  42.  
  43. /* The user must define the external function `decimal_error'
  44.    which is called with two arguments to report errors in this package.
  45.    The two arguments may be passed to `printf' to print a message. */
  46.  
  47. /* Structure that represents a decimal number */
  48.  
  49. struct decimal
  50. {
  51.   unsigned int sign: 1;        /* One for negative number */
  52.                 /* The sign should always be zero for the number 0 */
  53.   int after: 15;        /* number of fraction digits */
  54.   unsigned short before;    /* number of non-fraction digits */
  55.   unsigned short refcnt;    /* number of pointers to this number */
  56.                 /* (used by calling program) */
  57.   char contents[1];        /* the digits themselves, least significant first. */
  58.                 /* digits are just numbers 0 .. RADIX-1 */
  59. };
  60.  
  61. /* There may never be leading nonfraction zeros or trailing fraction
  62.    zeros in a number.  They must be removed by all the arithmetic
  63.    functions.  Therefore, the number zero always has no digits stored. */
  64.  
  65. typedef struct decimal *decimal;
  66.  
  67. /* Decimal numbers are always passed around as pointers.
  68.    All the external entries in this file allocate new numbers
  69.    using `malloc' to store values in.
  70.    They never modify their arguments or any existing numbers. */
  71.  
  72. /* Return the total number of digits stored in the number `b' */
  73. #define LENGTH(b) ((b)->before + (b)->after)
  74.  
  75. /* Some constant decimal numbers */
  76.  
  77.  
  78. #define DECIMAL_ZERO &decimal_zero
  79.  
  80.  
  81. #define DECIMAL_ONE &decimal_one
  82.  
  83. #define DECIMAL_HALF &decimal_half
  84.  
  85. decimal decimal_add (), decimal_sub (), decimal_mul (), decimal_div ();
  86. decimal decimal_mul_dc (), decimal_mul_rounded (), decimal_rem ();
  87. decimal decimal_round_digits ();
  88. decimal make_decimal (), decimal_copy (), decimal_parse ();
  89. decimal decimal_sqrt (), decimal_expt ();
  90.  
  91. void decimal_print ();
  92.  
  93. /* End of decimal.h */
  94.