1 /********************************************************************/ 2 /* */ 3 /* flt_rtl.h Primitive actions for the float type. */ 4 /* Copyright (C) 1989 - 2010 Thomas Mertes */ 5 /* */ 6 /* This file is part of the Seed7 Runtime Library. */ 7 /* */ 8 /* The Seed7 Runtime Library is free software; you can */ 9 /* redistribute it and/or modify it under the terms of the GNU */ 10 /* Lesser General Public License as published by the Free Software */ 11 /* Foundation; either version 2.1 of the License, or (at your */ 12 /* option) any later version. */ 13 /* */ 14 /* The Seed7 Runtime Library is distributed in the hope that it */ 15 /* will be useful, but WITHOUT ANY WARRANTY; without even the */ 16 /* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR */ 17 /* PURPOSE. See the GNU Lesser General Public License for more */ 18 /* details. */ 19 /* */ 20 /* You should have received a copy of the GNU Lesser General */ 21 /* Public License along with this program; if not, write to the */ 22 /* Free Software Foundation, Inc., 51 Franklin Street, */ 23 /* Fifth Floor, Boston, MA 02110-1301, USA. */ 24 /* */ 25 /* Module: Seed7 Runtime Library */ 26 /* File: seed7/src/flt_rtl.h */ 27 /* Changes: 1993, 1994, 2005, 2010 Thomas Mertes */ 28 /* Content: Primitive actions for the float type. */ 29 /* */ 30 /********************************************************************/ 31 32 #if FLOAT_ZERO_DIV_ERROR 33 extern const rtlValueUnion f_const[]; 34 #define NOT_A_NUMBER f_const[0].floatValue 35 #define POSITIVE_INFINITY f_const[1].floatValue 36 #define NEGATIVE_INFINITY f_const[2].floatValue 37 #else 38 #define NOT_A_NUMBER ( 0.0 / 0.0) 39 #define POSITIVE_INFINITY ( 1.0 / 0.0) 40 #define NEGATIVE_INFINITY (-1.0 / 0.0) 41 #endif 42 43 #define DOUBLE_TO_CHAR_BUFFER_SIZE 1024 44 45 46 void setupFloat (void); 47 int64Type getMantissaAndExponent (double doubleValue, int *binaryExponent); 48 double setMantissaAndExponent (int64Type intMantissa, int binaryExponent); 49 memSizeType doubleToCharBuffer (const double doubleValue, 50 const double largeNumber, const char *format, char *buffer); 51 intType fltCmp (floatType number1, floatType number2); 52 53 #if !FREXP_FUNCTION_OKAY 54 floatType fltDecompose (const floatType number, intType *const exponent); 55 #endif 56 57 striType fltDgts (floatType number, intType precision); 58 59 #if !FLOAT_COMPARISON_OKAY 60 boolType fltEq (floatType number1, floatType number2); 61 #endif 62 63 #if EXP_FUNCTION_OKAY 64 #define fltExp(exponent) exp(exponent) 65 #else 66 floatType fltExp (floatType exponent); 67 #endif 68 69 #if HAS_EXPM1 70 #define fltExpM1(exponent) expm1(exponent) 71 #else 72 floatType fltExpM1 (floatType exponent); 73 #endif 74 75 #if !FLOAT_COMPARISON_OKAY 76 boolType fltGe (floatType number1, floatType number2); 77 boolType fltGt (floatType number1, floatType number2); 78 #endif 79 80 floatType fltIPow (floatType base, intType exponent); 81 boolType fltIsNegativeZero (floatType number); 82 83 #if LDEXP_FUNCTION_OKAY 84 #define fltLdexp(number, exponent) ldexp(number, exponent) 85 #else 86 floatType fltLdexp (floatType number, int exponent); 87 #endif 88 89 #if !FLOAT_COMPARISON_OKAY 90 boolType fltLe (floatType number1, floatType number2); 91 #endif 92 93 #if LOG_FUNCTION_OKAY 94 #define fltLog(number) log(number) 95 #else 96 floatType fltLog (floatType number); 97 #endif 98 99 #if LOG10_FUNCTION_OKAY 100 #define fltLog10(number) log10(number) 101 #else 102 floatType fltLog10 (floatType number); 103 #endif 104 105 #if HAS_LOG1P 106 #define fltLog1p(number) log1p(number) 107 #else 108 floatType fltLog1p (floatType number); 109 #endif 110 111 #if LOG2_FUNCTION_OKAY 112 #define fltLog2(number) log2(number) 113 #else 114 floatType fltLog2 (floatType number); 115 #endif 116 117 #if !FLOAT_COMPARISON_OKAY 118 boolType fltLt (floatType number1, floatType number2); 119 #endif 120 121 floatType fltMod (floatType dividend, floatType divisor); 122 floatType fltParse (const const_striType stri); 123 124 #if POW_FUNCTION_OKAY 125 #define fltPow(base, exponent) pow(base, exponent) 126 #else 127 floatType fltPow (floatType base, floatType exponent); 128 #endif 129 130 floatType fltRand (floatType low, floatType high); 131 floatType fltRandNoChk (floatType low, floatType high); 132 133 #if FMOD_FUNCTION_OKAY 134 #define fltRem(dividend, divisor) fmod(dividend, divisor) 135 #else 136 floatType fltRem (floatType dividend, floatType divisor); 137 #endif 138 139 striType fltSci (floatType number, intType precision); 140 141 #if SQRT_FUNCTION_OKAY 142 #define fltSqrt(number) sqrt(number) 143 #else 144 floatType fltSqrt (floatType number); 145 #endif 146 147 striType fltStr (floatType number); 148