File indexing completed on 2024-05-12 05:55:11

0001 /* floatcommon.h: header file for convenience functions, based on 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 
0032 #ifndef FLOATCOMMON_H
0033 # define FLOATCOMMON_H
0034 #include "floatnum.h"
0035 
0036 #ifdef __cplusplus
0037 extern "C" {
0038 #endif
0039 
0040 /* helper, checks parameters. Sets float_error to NaNOperand
0041    or InvalidPrecision and sets <x> to NaN, if the parameters do
0042    not meet the requirements of routines for higher mathematical
0043    functions, and returns 0 in this case */
0044 char chckmathparam(floatnum x, int digits);
0045 
0046 /* helper, determines, how many decimal digits the exponent of <x> has.
0047    If the exponent is 0, -1 is returned */
0048 int logexp(cfloatnum x);
0049 
0050 /* helper, returns the <digits> first decimal digits and the sign of a
0051    significand, encoded in an integer. */
0052 int leadingdigits(cfloatnum x, int digits);
0053 
0054 /* convenience wrapper for float_setscientific, setting the last
0055    parameter to NULLTERMINATED */
0056 void float_setasciiz(floatnum x, const char* asciiz);
0057 
0058 /* convenience wrapper for float_add, adds a signed integer to <summand1>
0059    and places the result in <sum> */
0060 char float_addi(floatnum sum, cfloatnum summand1,
0061                int summand2, int digits);
0062 
0063 /* convenience wrapper for float_mul, multiplies a signed integer with
0064    <factor1> and places the result in <product> */
0065 char float_muli(floatnum product, cfloatnum factor1,
0066                int factor2, int digits);
0067 
0068 /* convenience wrapper for float_div, divides <dividend> by a signed integer
0069    and places the result in <quotient> */
0070 char float_divi(floatnum quotient, cfloatnum dividend,
0071                int divisor, int digits);
0072 
0073 /* convenience wrapper for float_cmp: compares the absolute value of
0074    both operands */
0075 int float_abscmp(floatnum x, floatnum y);
0076 
0077 /* convenience wrapper for float_div, returns 1/<x> */
0078 char float_reciprocal(floatnum x, int digits);
0079 
0080 /* compares two numbers in a normal fashion, but returns equal, if their
0081    relative difference is less than 1e-<digits>, i.e.
0082    |(x-y)/max(x,y)| < 1e-<digits> */
0083 int float_relcmp(floatnum x, floatnum y, int digits);
0084 
0085 /* returns whether x is an integer */
0086 char float_isinteger(cfloatnum x);
0087 
0088 /* returns the integer part of x as integer. If x exceeds the
0089    integer range, 0 is returned */
0090 int float_asinteger(cfloatnum x);
0091 
0092 /* rounds x in TONEAREST mode. If x overflows, the rounding is reverted.
0093    Does not report errors */
0094 void float_checkedround(floatnum x, int digits);
0095 
0096 /* a fast way to multiply with a power of ten, does not set float_error
0097    on overflow or NaN, returns silently NaN instead*/
0098 void float_addexp(floatnum x, int smd);
0099 
0100 /* returns 0, if the integer part of x is even */
0101 char float_isodd(floatnum x);
0102 
0103 /* an extension of float_int: you can choose the round mode
0104    errors: FLOAT_NANOPERAND
0105            FLOAT_OVERFLOW (if EXP_MAX is really small) */
0106 char float_roundtoint(floatnum x, roundmode mode);
0107 
0108 float float_asfloat(cfloatnum x);
0109 
0110 void float_setfloat(floatnum dest, float x);
0111 
0112 float aprxsqrt(float x);
0113 float aprxln(float x);
0114 float aprxlog10(float x);
0115 float aprxlog2(float x);
0116 float aprxlngamma(float x);
0117 float aprxlog10fn(cfloatnum x);
0118 
0119 #ifdef __cplusplus
0120 }
0121 #endif
0122 
0123 #endif /* FLOATCOMMON_H */