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

0001 /* floathmath.h: higher mathematical functions, based on floatnum. */
0002 /*
0003     Copyright (C) 2007, 2008 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 
0032 #ifndef FLOATHMATH_H
0033 #define FLOATHMATH_H
0034 
0035 #include "floatnum.h"
0036 
0037 #ifdef __cplusplus
0038 extern "C" {
0039 #endif
0040 
0041 /* evaluates ln(1+x) for x > -1. This function is especially useful
0042    for small x, where its computation is more precise than that of
0043    float_ln.
0044    In case of an error, x is set to NaN and 0 is returned.
0045    Errors: NaNOperand
0046            InvalidPrecision (digits > MATHPRECISION)
0047            OutOfDomain */
0048 char float_lnxplus1(floatnum x, int digits);
0049 
0050 /* evaluates ln x (the logarithm to base e) for x > 0.
0051    Near x == 0, this function yields better results than float_lnxplus1.
0052    In case of an error, x is set to NaN and 0 is returned.
0053    Errors: NaNOperand
0054            InvalidPrecision (digits > MATHPRECISION)
0055            OutOfDomain */
0056 char float_ln(floatnum x, int digits);
0057 
0058 /* evaluates lg x (the logarithm to base 10) for x > 0.
0059    In case of an error, x is set to NaN and 0 is returned.
0060    Errors: NaNOperand
0061            InvalidPrecision (digits > MATHPRECISION)
0062            OutOfDomain */
0063 char float_lg(floatnum x, int digits);
0064 
0065 /* evaluates lb x (the logarithm to base 2) for x > 0.
0066    In case of an error, x is set to NaN and 0 is returned.
0067    Errors: NaNOperand
0068            InvalidPrecision (digits > MATHPRECISION)
0069            OutOfDomain */
0070 char float_lb(floatnum x, int digits);
0071 
0072 /* evaluates arsinh x, the inverse function of sinh.
0073    In case of an error, x is set to NaN and 0 is returned.
0074    Errors: NaNOperand
0075            InvalidPrecision (digits > MATHPRECISION) */
0076 char float_arsinh(floatnum x, int digits);
0077 
0078 /* evaluates arcosh x, the inverse function of cosh, for
0079    x >= 1.
0080    In case of an error, x is set to NaN and 0 is returned.
0081    Errors: NaNOperand
0082            InvalidPrecision (digits > MATHPRECISION)
0083            OutOfDomain */
0084 char float_arcosh(floatnum x, int digits);
0085 
0086 /* evaluates artanh x, the inverse function of tanh, for
0087    |x| < 1.
0088    In case of an error, x is set to NaN and 0 is returned.
0089    Errors: NaNOperand
0090            InvalidPrecision (digits > MATHPRECISION)
0091            OutOfDomain */
0092 char float_artanh(floatnum x, int digits);
0093 
0094 /* evaluates artanh (1+x), for -2 < x <= 0. This function is
0095    especially useful, if you want to compute values near the
0096    pole at x == 1.
0097    In case of an error, x is set to NaN and 0 is returned.
0098    Errors: NaNOperand
0099            InvalidPrecision (digits > MATHPRECISION)
0100            OutOfDomain */
0101 char float_artanhxplus1(floatnum x, int digits);
0102 
0103 /* evaluates arcosh (1+x), for x >= 0. This function is
0104    especially useful, if you want to compute values near the
0105    singularity of arcosh at x == 1.
0106    In case of an error, x is set to NaN and 0 is returned.
0107    Errors: NaNOperand
0108            InvalidPrecision (digits > MATHPRECISION)
0109            OutOfDomain */
0110 char float_arcoshxplus1(floatnum x, int digits);
0111 
0112 /* evaluates exp(x)
0113    In case of an error, x is set to NaN and 0 is returned.
0114    Errors: Underflow
0115            Overflow
0116            NaNOperand
0117            InvalidPrecision (digits > MATHPRECISION) */
0118 char float_exp(floatnum x, int digits);
0119 
0120 /* evaluates exp(x)-1. Use this in the neighbourhood of x == 0.
0121    In case of an error, x is set to NaN and 0 is returned.
0122    Errors: Overflow
0123            NaNOperand
0124            InvalidPrecision (digits > MATHPRECISION) */
0125 char float_expminus1(floatnum x, int digits);
0126 
0127 /* evaluates cosh(x).
0128    In case of an error, x is set to NaN and 0 is returned.
0129    Errors: Overflow
0130            NaNOperand
0131            InvalidPrecision (digits > MATHPRECISION) */
0132 char float_cosh(floatnum x, int digits);
0133 
0134 /* evaluates cosh(x) - 1. Yields better results in the
0135    neighbourhood of x == 0 than float_cosh.
0136    In case of an error, x is set to NaN and 0 is returned.
0137    Errors: Underflow
0138            Overflow
0139            NaNOperand
0140            InvalidPrecision (digits > MATHPRECISION) */
0141 char float_coshminus1(floatnum x, int digits);
0142 
0143 /* evaluates sinh(x).
0144    In case of an error, x is set to NaN and 0 is returned.
0145    Errors: Overflow
0146            NaNOperand
0147            InvalidPrecision (digits > MATHPRECISION) */
0148 char float_sinh(floatnum x, int digits);
0149 
0150 /* evaluates tanh(x).
0151    In case of an error, x is set to NaN and 0 is returned.
0152    Errors: NaNOperand
0153            InvalidPrecision (digits > MATHPRECISION) */
0154 char float_tanh(floatnum x, int digits);
0155 
0156 /* evaluates tanh(x)-1. Yields better results for large x > 0,
0157    when tanh x approx.== 1, than float_tanh.
0158    In case of an error, x is set to NaN and 0 is returned.
0159    Errors: Underflow
0160            NaNOperand
0161            InvalidPrecision (digits > MATHPRECISION) */
0162 char float_tanhminus1(floatnum x, int digits);
0163 
0164 /* evaluates 10^x. No optimization is applied for integer
0165    exponents.
0166    In case of an error, x is set to NaN and 0 is returned.
0167    Errors: Underflow
0168            Overflow
0169            NaNOperand
0170            InvalidPrecision (digits > MATHPRECISION) */
0171 char float_power10(floatnum x, int digits);
0172 
0173 /* evaluates arctan x, yielding a result -pi/2 < result < pi/2.
0174    In case of an error, x is set to NaN and 0 is returned.
0175    Errors: NaNOperand
0176            InvalidPrecision (digits > MATHPRECISION) */
0177 char float_arctan(floatnum x, int digits);
0178 
0179 /* evaluates arcsin x for -1 <= x <= 1, yielding a result
0180    -pi/2 <= result <= pi/2.
0181    In case of an error, x is set to NaN and 0 is returned.
0182    Errors: OutOfDomain
0183            NaNOperand
0184            InvalidPrecision (digits > MATHPRECISION) */
0185 char float_arcsin(floatnum x, int digits);
0186 
0187 /* evaluates arccos x for -1 <= x <= 1, yielding a result
0188    0 <= result <= pi.
0189    In case of an error, x is set to NaN and 0 is returned.
0190    Errors: OutOfDomain
0191            NaNOperand
0192            InvalidPrecision (digits > MATHPRECISION) */
0193 char float_arccos(floatnum x, int digits);
0194 /* evaluates arccos (1+x) for -2 <= x <= 0, yielding a result
0195    0 <= result <= pi. This function is more precise in the
0196    neighbourhood of x == 0 than float_arccos.
0197    In case of an error, x is set to NaN and 0 is returned.
0198    Errors: Underflow
0199            Overflow
0200            NaNOperand
0201            InvalidPrecision (digits > MATHPRECISION) */
0202 char float_arccosxplus1(floatnum x, int digits);
0203 
0204 /* evaluates tan x. For extreme large x, the periodicity
0205    of tan is not recognized any more, and a FLOAT_UNSTABLE
0206    error is reported. The same holds, if x is too near to
0207    a pole of tan, more precise, if |x-0.5*n*pi| < 1e-<digits>
0208    for some n.
0209    In case of an error, x is set to NaN and 0 is returned.
0210    Errors: EvalUnstable
0211            NaNOperand
0212            InvalidPrecision (digits > MATHPRECISION) */
0213 char float_tan(floatnum x, int digits);
0214 
0215 /* evaluates sin x. For extreme large x, the periodicity
0216    of sin is not recognized any more, and a FLOAT_UNSTABLE
0217    error is reported.
0218    In case of an error, x is set to NaN and 0 is returned.
0219    Errors: EvalUnstable
0220            NaNOperand
0221            InvalidPrecision (digits > MATHPRECISION) */
0222 char float_sin(floatnum x, int digits);
0223 
0224 /* evaluates cos x. For extreme large x, the periodicity
0225    of sin is not recognized any more, and a FLOAT_UNSTABLE
0226    error is reported.
0227    In case of an error, x is set to NaN and 0 is returned.
0228    Errors: EvalUnstable
0229            NaNOperand
0230            InvalidPrecision (digits > MATHPRECISION) */
0231 char float_cos(floatnum x, int digits);
0232 
0233 /* evaluates cos x - 1. In the neighbourhood of x==0, when
0234    cos x approx.== 1, this function yields better results
0235    than float_cos.
0236    For extreme large x, the periodicity
0237    of sin is not recognized any more, and a FLOAT_UNSTABLE
0238    error is reported.
0239    In case of an error, x is set to NaN and 0 is returned.
0240    Errors: Undeflow
0241            EvalUnstable
0242            NaNOperand
0243            InvalidPrecision (digits > MATHPRECISION) */
0244 char float_cosminus1(floatnum x, int digits);
0245 
0246 /* evaluates base^exponent
0247    In case of an error, x is set to NaN and 0 is returned.
0248    Errors: Underflow
0249            Overflow
0250            OutOfDomain (base <= 0 and most exponents)
0251            ZeroDivide  ( base == 0 and exponent negative)
0252            NaNOperand
0253            InvalidPrecision (digits > maxprecision-14) */
0254 char float_raisei(floatnum power, cfloatnum base,
0255                  int exponent, int digits);
0256 
0257 /* evaluates base^exponent
0258    In case of an error, x is set to NaN and 0 is returned.
0259    Errors: Underflow
0260            Overflow
0261            OutOfDomain (base <= 0 and most exponents)
0262            ZeroDivide  (base == 0 and exponent negative)
0263            NaNOperand
0264            InvalidPrecision (digits > MATHPRECISION) */
0265 char float_raise(floatnum power, cfloatnum base,
0266                  cfloatnum exponent, int digits);
0267 
0268 /* evaluates Gamma(x) = (x-1)!
0269    In case of an error, x is set to NaN and 0 is returned.
0270    Errors: Underflow
0271            Overflow
0272            ZeroDivide  (for integers <= 0)
0273            NaNOperand
0274            InvalidPrecision (digits > MATHPRECISION) */
0275 char float_gamma(floatnum x, int digits);
0276 
0277 /* evaluates ln(Gamma(x)) = ln((x-1)!)
0278    In case of an error, x is set to NaN and 0 is returned.
0279    Errors: Overflow
0280            OutOfDomain  (for x <= 0)
0281            NaNOperand
0282            InvalidPrecision (digits > MATHPRECISION) */
0283 char float_lngamma(floatnum x, int digits);
0284 
0285 /* evaluates x!
0286    In case of an error, x is set to NaN and 0 is returned.
0287    Errors: Underflow
0288            Overflow
0289            ZeroDivide  (for integers < 0)
0290            NaNOperand
0291            InvalidPrecision (digits > MATHPRECISION) */
0292 char float_factorial(floatnum x, int digits);
0293 
0294 /* evaluates gamma(x+delta)/gamma(x). If delta is a positive integer, this
0295    is the Pochhammer symbol x*(x+1)*...*(x+delta-1). The poles of the
0296    gamma function are handled appropriately.
0297    Errors: Underflow
0298            Overflow
0299            ZeroDivide  (not annihilated pole in the nominator)
0300            NaNOperand
0301            InvalidPrecision (digits > MATHPRECISION) */
0302 char float_pochhammer(floatnum x, cfloatnum delta, int digits);
0303 
0304 /* evaluates erf(x).
0305            NaNOperand
0306            InvalidPrecision (digits > MATHPRECISION) */
0307 char float_erf(floatnum x, int digits);
0308 
0309 /* evaluates erfc(x).
0310            Underflow
0311            NaNOperand
0312            InvalidPrecision (digits > MATHPRECISION) */
0313 char float_erfc(floatnum x, int digits);
0314 
0315 /* cuts off the fraction part of <x> and complements the bits
0316    in the 2's complement representation of <x> then. The
0317    corresponding integer of the result is stored back in <x>.
0318    In case of an error, <x> is set to NaN and 0 is returned.
0319    Errors: OutOfLogicRange
0320            NaNOperand */
0321 char float_not(floatnum x);
0322 
0323 /* uses the integer parts of <x> and <y> and builds their
0324    2's complement representation. The resulting strings
0325    are and-ed and the corresponding integer is stored
0326    in dest.
0327    In case of an error, <dest> is set to NaN and 0 is returned.
0328    Errors: OutOfLogicRange
0329            NaNOperand */
0330 char float_and(floatnum dest, cfloatnum x, cfloatnum y);
0331 
0332 /* uses the integer parts of x and y and builds their
0333    2's complement representation. The resulting strings
0334    are or-ed and the corresponding integer is stored
0335    in dest.
0336    In case of an error, <dest> is set to NaN and 0 is returned.
0337    Errors: OutOfLogicRange
0338            NaNOperand */
0339 char float_or(floatnum dest, cfloatnum x, cfloatnum y);
0340 
0341 /* uses the integer parts of <x> and <y> and builds their
0342    2's complement representation. The resulting strings
0343    are xor-ed and the corresponding integer is stored
0344    in dest.
0345    In case of an error, <dest> is set to NaN and 0 is returned.
0346    Errors: OutOfLogicRange
0347            NaNOperand */
0348 char float_xor(floatnum dest, cfloatnum x, cfloatnum y);
0349 
0350 /* uses the integer part of <x> and builds its 2's complement
0351    representation as LOGICRANGE bits. The resulting bitstring
0352    is then shifted y times to the left. Shifted out bits are dropped,
0353    to the right 0 bits are fed in.
0354    The corresponding integer of the resulting bitstring is stored
0355    in <dest>.
0356    <y> has to be an integer or an error is reported. If it is negative,
0357    this operation turns into a shift right.
0358    In case of an error, <dest> is set to NaN and 0 is returned.
0359    Errors: OutOfDomain (y not an integer)
0360            OutOfLogicRange
0361            NaNOperand */
0362 char float_shl(floatnum dest, cfloatnum x, cfloatnum y);
0363 
0364 /* uses the integer part of <x> and builds its 2's complement
0365    representation as LOGICRANGE bits. The resulting bitstring
0366    is then shifted y times to the right. Shifted out bits are dropped,
0367    to the left the sign bit is duplicated.
0368    The corresponding integer of the resulting bitstring is stored
0369    in <dest>.
0370    <y> has to be an integer or an error is reported. If it is negative,
0371    this operation turns into a shift left.
0372    In case of an error, <dest> is set to NaN and 0 is returned.
0373    Errors: OutOfDomain (y not an integer)
0374            OutOfLogicRange
0375            NaNOperand */
0376 char float_shr(floatnum dest, cfloatnum x, cfloatnum y);
0377 
0378 #ifdef __cplusplus
0379 }
0380 #endif
0381 
0382 #endif /* FLOATLOG_H */