SpeedCrunch  0.11
/usr/src/RPM/BUILD/speedcrunch-0.11/src/math/floatconfig.h
Go to the documentation of this file.
00001 /* floatdefines.h: basic settings in floatnum. */
00002 /*
00003     Copyright (C) 2007 - 2009 Wolf Lammen.
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License , or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; see the file COPYING.  If not, write to:
00017 
00018       The Free Software Foundation, Inc.
00019       59 Temple Place, Suite 330
00020       Boston, MA 02111-1307 USA.
00021 
00022 
00023     You may contact the author by:
00024        e-mail:  ookami1 <at> gmx <dot> de
00025        mail:  Wolf Lammen
00026               Oertzweg 45
00027               22307 Hamburg
00028               Germany
00029 *************************************************************************/
00030 
00031 /* this file contains the basic settings, that control the overall
00032    behaviour of floatnum and derivates.
00033    Uncomment or set any of the following defines according to your needs.
00034 */
00035 
00036 #ifndef _FLOATCONFIG_H
00037 #define _FLOATCONFIG_H
00038 
00039 /* FLOATDEBUG introduces some extensions to floatnum, so you can
00040    easily follow operations of floatnum in a debugger like ddd.
00041    Uncomment this, if you develop code based on floatnum, and if you want
00042    to look into floatnum variables during a debugger session. */
00043 // #define FLOATDEBUG
00044 
00045 /* enables a pre-defined set of macros so that a regression test suite
00046    of floatnum can be executed. These settings are such that corner cases
00047    can easily be triggered. The settings are not useful in a real application
00048    of floatnum.
00049    Uncomment this if you want to run the standard regression test suite
00050    of floatnum */
00051 // #define _FLOATNUMTEST
00052 
00053 /* floatnum uses bc's bc_num format to store and operate on data. Since
00054    bc_num is an arbitrary precision format, operands may grow to extreme
00055    sizes, where complex operations take considerable time to execute,
00056    up to an hour or more. floatconfig defines a guard value to avoid extreme
00057    long operands. Any request to produce a result of more than MAXDIGITS
00058    digits is considered an error and yields a NaN result.
00059    When setting this value, bear in mind, this is a global value that
00060    effects internal operations as well as 'user' requests. When using
00061    the routines for transcendent mathematical functions, you should allow
00062    extra 14 digits, so that operations like float_exp do not fail when
00063    they compute something near maximum precision. */
00064 #define MAXDIGITS 250
00065 
00066 /* the number of bits into which an exponent of a floatnum is encoded.
00067    In order to avoid integer overflow, this should be at least two bits
00068    less than the bits in the integer type chosen for the exponent.
00069    The default is two bit less than the size of an int */
00070 // #define BITS_IN_EXP 30
00071 
00072 /* floatnum puts an upper limit on the base 10 exponent of its numbers that
00073    is based on the size of an integer, but even for 16 bit integers this
00074    limit is as big as 4095. Real applications usually do not need such
00075    big numbers. If you want to limit the range of possible numbers, set
00076    this value accordingly. An operation result exceeding this limit is
00077    converted into a NaN, and an overflow/underflow is reported. The
00078    default is the maximum positive value that can be encoded in
00079    BITS_IN_EXP bits.
00080    If you change EXPMAX, you might want to reduce BITS_IN_EXP as well. */
00081 /* #define EXPMAX 5000 */
00082 
00083 /* The precision of basic operations like + or * is limited by MAXDIGITS.
00084    In addition, some higher mathematical functions involve constants,
00085    that, of course, are stored to a limited precision only. This puts
00086    another bound on floatnum, described by the value MATHPRECISION.
00087    Since procedures for higher mathematical functions employ basic operations
00088    to determine their result, MATHPRECISION is <= MAXDIGITS.
00089    The current math library version of floatnum limits higher mathematical
00090    functions to 100 digits precision.
00091    One can say, MATHPRECISION describes the granularity of the number
00092    space, because higher functions do not (reliably) produce different results for
00093    values closer to each other than this granularity.
00094    You may re-define granularity by setting DECPRECISION. This will never
00095    bypass MATHPRECISION, being always the limit for the math library,
00096    but basic operations may benefit from finer granularity, up to the
00097    overall limit MAXDIGITS.
00098    If you lower granularity, that saves some memory and evaluation time in
00099    a few places.
00100    Granularity means that integers with more than DECPRECISION digits
00101    might not be saved without loss of digits. So DECPRECISION defines
00102    the integer range of floatnum.
00103    Because base convertion and logic operations are integer based, both
00104    are limited by DECPRECISION as well.
00105    By default, DECPRECISION is set to MATHPRECISION */
00106 #define DECPRECISION 78
00107 
00108 /* The integer domain of logical functions is a true subset of the integer range,
00109    because, according to their nature, they operate modulo a power of two, so
00110    the limit on their input is best chosen to be a power of 2.
00111    If you do not declare a limit here, an appropriate value is derived from
00112    DECPRECISION. If you change this value, make sure 2^LOGICRANGE
00113    is less than 10^DECPRECISION */
00114  #define LOGICRANGE 256
00115 
00116 /***************************************************************************
00117 
00118                       END OF USER SETABLE DEFINES
00119 
00120 ***************************************************************************/
00121 
00122 /* the limit of the math library */
00123 #define MATHPRECISION 100
00124 
00125 #if defined(_FLOATNUMTEST)
00126 #  undef MAXDIGITS
00127 #  undef MATHPRECISION
00128 #  undef DECPRECISION
00129 #  undef LOGICRANGE
00130 #  define MAXDIGITS 130
00131 #  define MATHPRECISION 130
00132 #  define LOGICRANGE 96
00133 #endif
00134 
00135 #define MAXBITS_IN_EXP (sizeof(int)*8-2)
00136 #define MAXEXP ((1 << MAXBITS_IN_EXP) - 1)
00137 
00138 #ifndef BITS_IN_EXP
00139 /* we need 2 extra bits during conversion, so that the exponent
00140    does not overflow while computing a base 2 expression */
00141 # define BITS_IN_EXP MAXBITS_IN_EXP
00142 #endif
00143 
00144 /* necessary width of an integer to hold all possible
00145    exponents after a conversion to another base */
00146 #define BITS_IN_HEXEXP   BITS_IN_EXP
00147 #define BITS_IN_OCTEXP   (BITS_IN_EXP + 1)
00148 #define BITS_IN_BINEXP   (BITS_IN_EXP + 2)
00149 
00150 #ifndef MAXDIGITS
00151 #  define MAXDIGITS 500
00152 #endif /* MAXDIGITS */
00153 
00154 #ifndef EXPMAX
00155 #  define EXPMAX ((1 << (BITS_IN_EXP-1)) - 1)
00156 #endif /* EXPMAX */
00157 
00158 #define EXPMIN (-EXPMAX - 1)
00159 
00160 #define EXPZERO ((int)((-1) << (sizeof(int)*8-1)))
00161 #define EXPNAN ((int)(~EXPZERO))
00162 
00163 #ifndef DECPRECISION
00164   #define DECPRECISION MATHPRECISION
00165 #endif
00166 #define BINPRECISION ((33219*DECPRECISION)/10000 + 1)
00167 #define OCTPRECISION ((11073*DECPRECISION)/10000 + 1)
00168 #define HEXPRECISION ((8305*DECPRECISION)/10000 + 1)
00169 
00170 #ifndef LOGICRANGE
00171 # define LOGICRANGE (16*((BINPRECISION-2)/16))
00172 #endif
00173 
00174 #endif /* _FLOATCONFIG_H */