SpeedCrunch  0.11
/usr/src/RPM/BUILD/speedcrunch-0.11/src/math/floatcommon.h
Go to the documentation of this file.
00001 /* floatcommon.h: header file for convenience functions, based on 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 
00032 #ifndef FLOATCOMMON_H
00033 # define FLOATCOMMON_H
00034 #include "floatnum.h"
00035 
00036 #ifdef __cplusplus
00037 extern "C" {
00038 #endif
00039 
00040 /* helper, checks parameters. Sets float_error to NaNOperand
00041    or InvalidPrecision and sets <x> to NaN, if the parameters do
00042    not meet the requirements of routines for higher mathematical
00043    functions, and returns 0 in this case */
00044 char chckmathparam(floatnum x, int digits);
00045 
00046 /* helper, determines, how many decimal digits the exponent of <x> has.
00047    If the exponent is 0, -1 is returned */
00048 int logexp(cfloatnum x);
00049 
00050 /* helper, returns the <digits> first decimal digits and the sign of a
00051    significand, encoded in an integer. */
00052 int leadingdigits(cfloatnum x, int digits);
00053 
00054 /* convenience wrapper for float_setscientific, setting the last
00055    parameter to NULLTERMINATED */
00056 void float_setasciiz(floatnum x, const char* asciiz);
00057 
00058 /* convenience wrapper for float_add, adds a signed integer to <summand1>
00059    and places the result in <sum> */
00060 char float_addi(floatnum sum, cfloatnum summand1,
00061                int summand2, int digits);
00062 
00063 /* convenience wrapper for float_mul, multiplies a signed integer with
00064    <factor1> and places the result in <product> */
00065 char float_muli(floatnum product, cfloatnum factor1,
00066                int factor2, int digits);
00067 
00068 /* convenience wrapper for float_div, divides <dividend> by a signed integer
00069    and places the result in <quotient> */
00070 char float_divi(floatnum quotient, cfloatnum dividend,
00071                int divisor, int digits);
00072 
00073 /* convenience wrapper for float_cmp: compares the absolute value of
00074    both operands */
00075 int float_abscmp(floatnum x, floatnum y);
00076 
00077 /* convenience wrapper for float_div, returns 1/<x> */
00078 char float_reciprocal(floatnum x, int digits);
00079 
00080 /* compares two numbers in a normal fashion, but returns equal, if their
00081    relative difference is less than 1e-<digits>, i.e.
00082    |(x-y)/max(x,y)| < 1e-<digits> */
00083 int float_relcmp(floatnum x, floatnum y, int digits);
00084 
00085 /* returns whether x is an integer */
00086 char float_isinteger(cfloatnum x);
00087 
00088 /* returns the integer part of x as integer. If x exceeds the
00089    integer range, 0 is returned */
00090 int float_asinteger(cfloatnum x);
00091 
00092 /* rounds x in TONEAREST mode. If x overflows, the rounding is reverted.
00093    Does not report errors */
00094 void float_checkedround(floatnum x, int digits);
00095 
00096 /* a fast way to multiply with a power of ten, does not set float_error
00097    on overflow or NaN, returns silently NaN instead*/
00098 void float_addexp(floatnum x, int smd);
00099 
00100 /* returns 0, if the integer part of x is even */
00101 char float_isodd(floatnum x);
00102 
00103 /* an extension of float_int: you can choose the round mode
00104    errors: FLOAT_NANOPERAND
00105            FLOAT_OVERFLOW (if EXP_MAX is really small) */
00106 char float_roundtoint(floatnum x, roundmode mode);
00107 
00108 float float_asfloat(cfloatnum x);
00109 
00110 void float_setfloat(floatnum dest, float x);
00111 
00112 float aprxsqrt(float x);
00113 float aprxln(float x);
00114 float aprxlog10(float x);
00115 float aprxlog2(float x);
00116 float aprxlngamma(float x);
00117 float aprxlog10fn(cfloatnum x);
00118 
00119 #ifdef __cplusplus
00120 }
00121 #endif
00122 
00123 #endif /* FLOATCOMMON_H */