SpeedCrunch  0.11
/usr/src/RPM/BUILD/speedcrunch-0.11/src/math/floathmath.h
Go to the documentation of this file.
00001 /* floathmath.h: higher mathematical functions, based on floatnum. */
00002 /*
00003     Copyright (C) 2007, 2008 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 FLOATHMATH_H
00033 #define FLOATHMATH_H
00034 
00035 #include "floatnum.h"
00036 
00037 #ifdef __cplusplus
00038 extern "C" {
00039 #endif
00040 
00041 /* evaluates ln(1+x) for x > -1. This function is especially useful
00042    for small x, where its computation is more precise than that of
00043    float_ln.
00044    In case of an error, x is set to NaN and 0 is returned.
00045    Errors: NaNOperand
00046            InvalidPrecision (digits > MATHPRECISION)
00047            OutOfDomain */
00048 char float_lnxplus1(floatnum x, int digits);
00049 
00050 /* evaluates ln x (the logarithm to base e) for x > 0.
00051    Near x == 0, this function yields better results than float_lnxplus1.
00052    In case of an error, x is set to NaN and 0 is returned.
00053    Errors: NaNOperand
00054            InvalidPrecision (digits > MATHPRECISION)
00055            OutOfDomain */
00056 char float_ln(floatnum x, int digits);
00057 
00058 /* evaluates lg x (the logarithm to base 10) for x > 0.
00059    In case of an error, x is set to NaN and 0 is returned.
00060    Errors: NaNOperand
00061            InvalidPrecision (digits > MATHPRECISION)
00062            OutOfDomain */
00063 char float_lg(floatnum x, int digits);
00064 
00065 /* evaluates lb x (the logarithm to base 2) for x > 0.
00066    In case of an error, x is set to NaN and 0 is returned.
00067    Errors: NaNOperand
00068            InvalidPrecision (digits > MATHPRECISION)
00069            OutOfDomain */
00070 char float_lb(floatnum x, int digits);
00071 
00072 /* evaluates arsinh x, the inverse function of sinh.
00073    In case of an error, x is set to NaN and 0 is returned.
00074    Errors: NaNOperand
00075            InvalidPrecision (digits > MATHPRECISION) */
00076 char float_arsinh(floatnum x, int digits);
00077 
00078 /* evaluates arcosh x, the inverse function of cosh, for
00079    x >= 1.
00080    In case of an error, x is set to NaN and 0 is returned.
00081    Errors: NaNOperand
00082            InvalidPrecision (digits > MATHPRECISION)
00083            OutOfDomain */
00084 char float_arcosh(floatnum x, int digits);
00085 
00086 /* evaluates artanh x, the inverse function of tanh, for
00087    |x| < 1.
00088    In case of an error, x is set to NaN and 0 is returned.
00089    Errors: NaNOperand
00090            InvalidPrecision (digits > MATHPRECISION)
00091            OutOfDomain */
00092 char float_artanh(floatnum x, int digits);
00093 
00094 /* evaluates artanh (1+x), for -2 < x <= 0. This function is
00095    especially useful, if you want to compute values near the
00096    pole at x == 1.
00097    In case of an error, x is set to NaN and 0 is returned.
00098    Errors: NaNOperand
00099            InvalidPrecision (digits > MATHPRECISION)
00100            OutOfDomain */
00101 char float_artanhxplus1(floatnum x, int digits);
00102 
00103 /* evaluates arcosh (1+x), for x >= 0. This function is
00104    especially useful, if you want to compute values near the
00105    singularity of arcosh at x == 1.
00106    In case of an error, x is set to NaN and 0 is returned.
00107    Errors: NaNOperand
00108            InvalidPrecision (digits > MATHPRECISION)
00109            OutOfDomain */
00110 char float_arcoshxplus1(floatnum x, int digits);
00111 
00112 /* evaluates exp(x)
00113    In case of an error, x is set to NaN and 0 is returned.
00114    Errors: Underflow
00115            Overflow
00116            NaNOperand
00117            InvalidPrecision (digits > MATHPRECISION) */
00118 char float_exp(floatnum x, int digits);
00119 
00120 /* evaluates exp(x)-1. Use this in the neighbourhood of x == 0.
00121    In case of an error, x is set to NaN and 0 is returned.
00122    Errors: Overflow
00123            NaNOperand
00124            InvalidPrecision (digits > MATHPRECISION) */
00125 char float_expminus1(floatnum x, int digits);
00126 
00127 /* evaluates cosh(x).
00128    In case of an error, x is set to NaN and 0 is returned.
00129    Errors: Overflow
00130            NaNOperand
00131            InvalidPrecision (digits > MATHPRECISION) */
00132 char float_cosh(floatnum x, int digits);
00133 
00134 /* evaluates cosh(x) - 1. Yields better results in the
00135    neighbourhood of x == 0 than float_cosh.
00136    In case of an error, x is set to NaN and 0 is returned.
00137    Errors: Underflow
00138            Overflow
00139            NaNOperand
00140            InvalidPrecision (digits > MATHPRECISION) */
00141 char float_coshminus1(floatnum x, int digits);
00142 
00143 /* evaluates sinh(x).
00144    In case of an error, x is set to NaN and 0 is returned.
00145    Errors: Overflow
00146            NaNOperand
00147            InvalidPrecision (digits > MATHPRECISION) */
00148 char float_sinh(floatnum x, int digits);
00149 
00150 /* evaluates tanh(x).
00151    In case of an error, x is set to NaN and 0 is returned.
00152    Errors: NaNOperand
00153            InvalidPrecision (digits > MATHPRECISION) */
00154 char float_tanh(floatnum x, int digits);
00155 
00156 /* evaluates tanh(x)-1. Yields better results for large x > 0,
00157    when tanh x approx.== 1, than float_tanh.
00158    In case of an error, x is set to NaN and 0 is returned.
00159    Errors: Underflow
00160            NaNOperand
00161            InvalidPrecision (digits > MATHPRECISION) */
00162 char float_tanhminus1(floatnum x, int digits);
00163 
00164 /* evaluates 10^x. No optimization is applied for integer
00165    exponents.
00166    In case of an error, x is set to NaN and 0 is returned.
00167    Errors: Underflow
00168            Overflow
00169            NaNOperand
00170            InvalidPrecision (digits > MATHPRECISION) */
00171 char float_power10(floatnum x, int digits);
00172 
00173 /* evaluates arctan x, yielding a result -pi/2 < result < pi/2.
00174    In case of an error, x is set to NaN and 0 is returned.
00175    Errors: NaNOperand
00176            InvalidPrecision (digits > MATHPRECISION) */
00177 char float_arctan(floatnum x, int digits);
00178 
00179 /* evaluates arcsin x for -1 <= x <= 1, yielding a result
00180    -pi/2 <= result <= pi/2.
00181    In case of an error, x is set to NaN and 0 is returned.
00182    Errors: OutOfDomain
00183            NaNOperand
00184            InvalidPrecision (digits > MATHPRECISION) */
00185 char float_arcsin(floatnum x, int digits);
00186 
00187 /* evaluates arccos x for -1 <= x <= 1, yielding a result
00188    0 <= result <= pi.
00189    In case of an error, x is set to NaN and 0 is returned.
00190    Errors: OutOfDomain
00191            NaNOperand
00192            InvalidPrecision (digits > MATHPRECISION) */
00193 char float_arccos(floatnum x, int digits);
00194 /* evaluates arccos (1+x) for -2 <= x <= 0, yielding a result
00195    0 <= result <= pi. This function is more precise in the
00196    neighbourhood of x == 0 than float_arccos.
00197    In case of an error, x is set to NaN and 0 is returned.
00198    Errors: Underflow
00199            Overflow
00200            NaNOperand
00201            InvalidPrecision (digits > MATHPRECISION) */
00202 char float_arccosxplus1(floatnum x, int digits);
00203 
00204 /* evaluates tan x. For extreme large x, the periodicity
00205    of tan is not recognized any more, and a FLOAT_UNSTABLE
00206    error is reported. The same holds, if x is too near to
00207    a pole of tan, more precise, if |x-0.5*n*pi| < 1e-<digits>
00208    for some n.
00209    In case of an error, x is set to NaN and 0 is returned.
00210    Errors: EvalUnstable
00211            NaNOperand
00212            InvalidPrecision (digits > MATHPRECISION) */
00213 char float_tan(floatnum x, int digits);
00214 
00215 /* evaluates sin x. For extreme large x, the periodicity
00216    of sin is not recognized any more, and a FLOAT_UNSTABLE
00217    error is reported.
00218    In case of an error, x is set to NaN and 0 is returned.
00219    Errors: EvalUnstable
00220            NaNOperand
00221            InvalidPrecision (digits > MATHPRECISION) */
00222 char float_sin(floatnum x, int digits);
00223 
00224 /* evaluates cos x. For extreme large x, the periodicity
00225    of sin is not recognized any more, and a FLOAT_UNSTABLE
00226    error is reported.
00227    In case of an error, x is set to NaN and 0 is returned.
00228    Errors: EvalUnstable
00229            NaNOperand
00230            InvalidPrecision (digits > MATHPRECISION) */
00231 char float_cos(floatnum x, int digits);
00232 
00233 /* evaluates cos x - 1. In the neighbourhood of x==0, when
00234    cos x approx.== 1, this function yields better results
00235    than float_cos.
00236    For extreme large x, the periodicity
00237    of sin is not recognized any more, and a FLOAT_UNSTABLE
00238    error is reported.
00239    In case of an error, x is set to NaN and 0 is returned.
00240    Errors: Undeflow
00241            EvalUnstable
00242            NaNOperand
00243            InvalidPrecision (digits > MATHPRECISION) */
00244 char float_cosminus1(floatnum x, int digits);
00245 
00246 /* evaluates base^exponent
00247    In case of an error, x is set to NaN and 0 is returned.
00248    Errors: Underflow
00249            Overflow
00250            OutOfDomain (base <= 0 and most exponents)
00251            ZeroDivide  ( base == 0 and exponent negative)
00252            NaNOperand
00253            InvalidPrecision (digits > maxprecision-14) */
00254 char float_raisei(floatnum power, cfloatnum base,
00255                  int exponent, int digits);
00256 
00257 /* evaluates base^exponent
00258    In case of an error, x is set to NaN and 0 is returned.
00259    Errors: Underflow
00260            Overflow
00261            OutOfDomain (base <= 0 and most exponents)
00262            ZeroDivide  (base == 0 and exponent negative)
00263            NaNOperand
00264            InvalidPrecision (digits > MATHPRECISION) */
00265 char float_raise(floatnum power, cfloatnum base,
00266                  cfloatnum exponent, int digits);
00267 
00268 /* evaluates Gamma(x) = (x-1)!
00269    In case of an error, x is set to NaN and 0 is returned.
00270    Errors: Underflow
00271            Overflow
00272            ZeroDivide  (for integers <= 0)
00273            NaNOperand
00274            InvalidPrecision (digits > MATHPRECISION) */
00275 char float_gamma(floatnum x, int digits);
00276 
00277 /* evaluates ln(Gamma(x)) = ln((x-1)!)
00278    In case of an error, x is set to NaN and 0 is returned.
00279    Errors: Overflow
00280            OutOfDomain  (for x <= 0)
00281            NaNOperand
00282            InvalidPrecision (digits > MATHPRECISION) */
00283 char float_lngamma(floatnum x, int digits);
00284 
00285 /* evaluates x!
00286    In case of an error, x is set to NaN and 0 is returned.
00287    Errors: Underflow
00288            Overflow
00289            ZeroDivide  (for integers < 0)
00290            NaNOperand
00291            InvalidPrecision (digits > MATHPRECISION) */
00292 char float_factorial(floatnum x, int digits);
00293 
00294 /* evaluates gamma(x+delta)/gamma(x). If delta is a positive integer, this
00295    is the Pochhammer symbol x*(x+1)*...*(x+delta-1). The poles of the
00296    gamma function are handled appropriately.
00297    Errors: Underflow
00298            Overflow
00299            ZeroDivide  (not annihilated pole in the nominator)
00300            NaNOperand
00301            InvalidPrecision (digits > MATHPRECISION) */
00302 char float_pochhammer(floatnum x, cfloatnum delta, int digits);
00303 
00304 /* evaluates erf(x).
00305            NaNOperand
00306            InvalidPrecision (digits > MATHPRECISION) */
00307 char float_erf(floatnum x, int digits);
00308 
00309 /* evaluates erfc(x).
00310            Underflow
00311            NaNOperand
00312            InvalidPrecision (digits > MATHPRECISION) */
00313 char float_erfc(floatnum x, int digits);
00314 
00315 /* cuts off the fraction part of <x> and complements the bits
00316    in the 2's complement representation of <x> then. The
00317    corresponding integer of the result is stored back in <x>.
00318    In case of an error, <x> is set to NaN and 0 is returned.
00319    Errors: OutOfLogicRange
00320            NaNOperand */
00321 char float_not(floatnum x);
00322 
00323 /* uses the integer parts of <x> and <y> and builds their
00324    2's complement representation. The resulting strings
00325    are and-ed and the corresponding integer is stored
00326    in dest.
00327    In case of an error, <dest> is set to NaN and 0 is returned.
00328    Errors: OutOfLogicRange
00329            NaNOperand */
00330 char float_and(floatnum dest, cfloatnum x, cfloatnum y);
00331 
00332 /* uses the integer parts of x and y and builds their
00333    2's complement representation. The resulting strings
00334    are or-ed and the corresponding integer is stored
00335    in dest.
00336    In case of an error, <dest> is set to NaN and 0 is returned.
00337    Errors: OutOfLogicRange
00338            NaNOperand */
00339 char float_or(floatnum dest, cfloatnum x, cfloatnum y);
00340 
00341 /* uses the integer parts of <x> and <y> and builds their
00342    2's complement representation. The resulting strings
00343    are xor-ed and the corresponding integer is stored
00344    in dest.
00345    In case of an error, <dest> is set to NaN and 0 is returned.
00346    Errors: OutOfLogicRange
00347            NaNOperand */
00348 char float_xor(floatnum dest, cfloatnum x, cfloatnum y);
00349 
00350 /* uses the integer part of <x> and builds its 2's complement
00351    representation as LOGICRANGE bits. The resulting bitstring
00352    is then shifted y times to the left. Shifted out bits are dropped,
00353    to the right 0 bits are fed in.
00354    The corresponding integer of the resulting bitstring is stored
00355    in <dest>.
00356    <y> has to be an integer or an error is reported. If it is negative,
00357    this operation turns into a shift right.
00358    In case of an error, <dest> is set to NaN and 0 is returned.
00359    Errors: OutOfDomain (y not an integer)
00360            OutOfLogicRange
00361            NaNOperand */
00362 char float_shl(floatnum dest, cfloatnum x, cfloatnum y);
00363 
00364 /* uses the integer part of <x> and builds its 2's complement
00365    representation as LOGICRANGE bits. The resulting bitstring
00366    is then shifted y times to the right. Shifted out bits are dropped,
00367    to the left the sign bit is duplicated.
00368    The corresponding integer of the resulting bitstring is stored
00369    in <dest>.
00370    <y> has to be an integer or an error is reported. If it is negative,
00371    this operation turns into a shift left.
00372    In case of an error, <dest> is set to NaN and 0 is returned.
00373    Errors: OutOfDomain (y not an integer)
00374            OutOfLogicRange
00375            NaNOperand */
00376 char float_shr(floatnum dest, cfloatnum x, cfloatnum y);
00377 
00378 #ifdef __cplusplus
00379 }
00380 #endif
00381 
00382 #endif /* FLOATLOG_H */