File indexing completed on 2024-05-12 17:22:32

0001 /* floatdefines.h: basic settings in floatnum. */
0002 /*
0003     Copyright (C) 2007 - 2009 Wolf Lammen.
0004 
0005     This program is free software; you can redistribute it and/or modify
0006     it under the terms of the GNU General Public License as published by
0007     the Free Software Foundation; either version 2 of the License , or
0008     (at your option) any later version.
0009 
0010     This program is distributed in the hope that it will be useful,
0011     but WITHOUT ANY WARRANTY; without even the implied warranty of
0012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013     GNU General Public License for more details.
0014 
0015     You should have received a copy of the GNU General Public License
0016     along with this program; see the file COPYING.  If not, write to:
0017 
0018       The Free Software Foundation, Inc.
0019       59 Temple Place, Suite 330
0020       Boston, MA 02111-1307 USA.
0021 
0022 
0023     You may contact the author by:
0024        e-mail:  ookami1 <at> gmx <dot> de
0025        mail:  Wolf Lammen
0026               Oertzweg 45
0027               22307 Hamburg
0028               Germany
0029 *************************************************************************/
0030 
0031 /* this file contains the basic settings, that control the overall
0032    behaviour of floatnum and derivates.
0033    Uncomment or set any of the following defines according to your needs.
0034 */
0035 
0036 #ifndef _FLOATCONFIG_H
0037 #define _FLOATCONFIG_H
0038 
0039 /* FLOATDEBUG introduces some extensions to floatnum, so you can
0040    easily follow operations of floatnum in a debugger like ddd.
0041    Uncomment this, if you develop code based on floatnum, and if you want
0042    to look into floatnum variables during a debugger session. */
0043 // #define FLOATDEBUG
0044 
0045 /* enables a pre-defined set of macros so that a regression test suite
0046    of floatnum can be executed. These settings are such that corner cases
0047    can easily be triggered. The settings are not useful in a real application
0048    of floatnum.
0049    Uncomment this if you want to run the standard regression test suite
0050    of floatnum */
0051 // #define _FLOATNUMTEST
0052 
0053 /* floatnum uses bc's bc_num format to store and operate on data. Since
0054    bc_num is an arbitrary precision format, operands may grow to extreme
0055    sizes, where complex operations take considerable time to execute,
0056    up to an hour or more. floatconfig defines a guard value to avoid extreme
0057    long operands. Any request to produce a result of more than MAXDIGITS
0058    digits is considered an error and yields a NaN result.
0059    When setting this value, bear in mind, this is a global value that
0060    effects internal operations as well as 'user' requests. When using
0061    the routines for transcendent mathematical functions, you should allow
0062    extra 14 digits, so that operations like float_exp do not fail when
0063    they compute something near maximum precision. */
0064 #define MAXDIGITS 250
0065 
0066 /* the number of bits into which an exponent of a floatnum is encoded.
0067    In order to avoid integer overflow, this should be at least two bits
0068    less than the bits in the integer type chosen for the exponent.
0069    The default is two bit less than the size of an int */
0070 // #define BITS_IN_EXP 30
0071 
0072 /* floatnum puts an upper limit on the base 10 exponent of its numbers that
0073    is based on the size of an integer, but even for 16 bit integers this
0074    limit is as big as 4095. Real applications usually do not need such
0075    big numbers. If you want to limit the range of possible numbers, set
0076    this value accordingly. An operation result exceeding this limit is
0077    converted into a NaN, and an overflow/underflow is reported. The
0078    default is the maximum positive value that can be encoded in
0079    BITS_IN_EXP bits.
0080    If you change EXPMAX, you might want to reduce BITS_IN_EXP as well. */
0081 /* #define EXPMAX 5000 */
0082 
0083 /* The precision of basic operations like + or * is limited by MAXDIGITS.
0084    In addition, some higher mathematical functions involve constants,
0085    that, of course, are stored to a limited precision only. This puts
0086    another bound on floatnum, described by the value MATHPRECISION.
0087    Since procedures for higher mathematical functions employ basic operations
0088    to determine their result, MATHPRECISION is <= MAXDIGITS.
0089    The current math library version of floatnum limits higher mathematical
0090    functions to 100 digits precision.
0091    One can say, MATHPRECISION describes the granularity of the number
0092    space, because higher functions do not (reliably) produce different results for
0093    values closer to each other than this granularity.
0094    You may re-define granularity by setting DECPRECISION. This will never
0095    bypass MATHPRECISION, being always the limit for the math library,
0096    but basic operations may benefit from finer granularity, up to the
0097    overall limit MAXDIGITS.
0098    If you lower granularity, that saves some memory and evaluation time in
0099    a few places.
0100    Granularity means that integers with more than DECPRECISION digits
0101    might not be saved without loss of digits. So DECPRECISION defines
0102    the integer range of floatnum.
0103    Because base convertion and logic operations are integer based, both
0104    are limited by DECPRECISION as well.
0105    By default, DECPRECISION is set to MATHPRECISION */
0106 #define DECPRECISION 78
0107 
0108 /* The integer domain of logical functions is a true subset of the integer range,
0109    because, according to their nature, they operate modulo a power of two, so
0110    the limit on their input is best chosen to be a power of 2.
0111    If you do not declare a limit here, an appropriate value is derived from
0112    DECPRECISION. If you change this value, make sure 2^LOGICRANGE
0113    is less than 10^DECPRECISION */
0114  #define LOGICRANGE 256
0115 
0116 /***************************************************************************
0117 
0118                       END OF USER SETABLE DEFINES
0119 
0120 ***************************************************************************/
0121 
0122 /* the limit of the math library */
0123 #define MATHPRECISION 100
0124 
0125 #if defined(_FLOATNUMTEST)
0126 #  undef MAXDIGITS
0127 #  undef MATHPRECISION
0128 #  undef DECPRECISION
0129 #  undef LOGICRANGE
0130 #  define MAXDIGITS 130
0131 #  define MATHPRECISION 130
0132 #  define LOGICRANGE 96
0133 #endif
0134 
0135 #define MAXBITS_IN_EXP (sizeof(int)*8-2)
0136 #define MAXEXP ((1 << MAXBITS_IN_EXP) - 1)
0137 
0138 #ifndef BITS_IN_EXP
0139 /* we need 2 extra bits during conversion, so that the exponent
0140    does not overflow while computing a base 2 expression */
0141 # define BITS_IN_EXP MAXBITS_IN_EXP
0142 #endif
0143 
0144 /* necessary width of an integer to hold all possible
0145    exponents after a conversion to another base */
0146 #define BITS_IN_HEXEXP   BITS_IN_EXP
0147 #define BITS_IN_OCTEXP   (BITS_IN_EXP + 1)
0148 #define BITS_IN_BINEXP   (BITS_IN_EXP + 2)
0149 
0150 #ifndef MAXDIGITS
0151 #  define MAXDIGITS 500
0152 #endif /* MAXDIGITS */
0153 
0154 #ifndef EXPMAX
0155 #  define EXPMAX ((1 << (BITS_IN_EXP-1)) - 1)
0156 #endif /* EXPMAX */
0157 
0158 #define EXPMIN (-EXPMAX - 1)
0159 
0160 #define EXPZERO ((int)((unsigned)(-1) << (sizeof(int)*8-1)))
0161 #define EXPNAN ((int)(~EXPZERO))
0162 
0163 #ifndef DECPRECISION
0164   #define DECPRECISION MATHPRECISION
0165 #endif
0166 #define BINPRECISION ((33219*DECPRECISION)/10000 + 1)
0167 #define OCTPRECISION ((11073*DECPRECISION)/10000 + 1)
0168 #define HEXPRECISION ((8305*DECPRECISION)/10000 + 1)
0169 
0170 #ifndef LOGICRANGE
0171 # define LOGICRANGE (16*((BINPRECISION-2)/16))
0172 #endif
0173 
0174 #endif /* _FLOATCONFIG_H */