2 * Header file for decimal.c (arbitrary precision decimal arithmetic)
4 * Copyright (C) 1984 Free Software Foundation, Inc.
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)
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.
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.
25 #define bcopy(s2, s1, n) memcpy (s1, s2, n)
30 #define bzero(b, l) memset (b, 0, l)
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. */
37 /* Currently, this is required to be even for this program to work. */
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. */
47 /* Structure that represents a decimal number */
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 */
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. */
65 typedef struct decimal *decimal;
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. */
72 /* Return the total number of digits stored in the number `b' */
73 #define LENGTH(b) ((b)->before + (b)->after)
75 /* Some constant decimal numbers */
78 #define DECIMAL_ZERO &decimal_zero
81 #define DECIMAL_ONE &decimal_one
83 #define DECIMAL_HALF &decimal_half
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 ();
91 void decimal_print ();
93 /* End of decimal.h */