Home | History | Annotate | Download | only in include
      1 /*
      2  * float.h
      3  * This file has no copyright assigned and is placed in the Public Domain.
      4  * This file is part of the mingw-runtime package.
      5  * No warranty is given; refer to the file DISCLAIMER.PD within the package.
      6  *
      7  * Constants related to floating point arithmetic.
      8  *
      9  * Also included here are some non-ANSI bits for accessing the floating
     10  * point controller.
     11  *
     12  */
     13 
     14 #if (defined (__GNUC__) && defined (__GNUC_MINOR__)) \
     15     || (defined(__clang__) && defined(__clang_major__))
     16 #if (__GNUC__ < 4  || (__GNUC__ == 4 && __GNUC_MINOR__ < 6)) \
     17     || (__clang_major__ >=3)
     18 #if !defined(_FLOAT_H___) && !defined(__FLOAT_H)
     19 #include_next <float.h>
     20 #endif
     21 #elif !defined (_FLOAT_H___)
     22 #if (__GNUC__ < 4)
     23 #error Corrupt install of gcc-s internal headers, or search order was changed.
     24 #else
     25 	/* #include_next <float_ginclude.h> */
     26 
     27    	/* Number of decimal digits, q, such that any floating-point number with q
     28    	   decimal digits can be rounded into a floating-point number with p radix b
     29 	   digits and back again without change to the q decimal digits,
     30 
     31 	   p * log10(b)			if b is a power of 10
     32 	   floor((p - 1) * log10(b))	otherwise
     33 	*/
     34 	#undef FLT_DIG
     35 	#undef DBL_DIG
     36 	#undef LDBL_DIG
     37 	#define FLT_DIG		__FLT_DIG__
     38 	#define DBL_DIG		__DBL_DIG__
     39 	#define LDBL_DIG	__LDBL_DIG__
     40 
     41 
     42 	/* Maximum representable finite floating-point number,
     43 
     44 	   (1 - b**-p) * b**emax
     45 	*/
     46 	#undef FLT_MAX
     47 	#undef DBL_MAX
     48 	#undef LDBL_MAX
     49 	#define FLT_MAX		__FLT_MAX__
     50 	#define DBL_MAX		__DBL_MAX__
     51 	#define LDBL_MAX	__LDBL_MAX__
     52 
     53 
     54 	/* Minimum normalized positive floating-point number, b**(emin - 1).  */
     55 	#undef FLT_MIN
     56 	#undef DBL_MIN
     57 	#undef LDBL_MIN
     58 	#define FLT_MIN		__FLT_MIN__
     59 	#define DBL_MIN		__DBL_MIN__
     60 	#define LDBL_MIN	__LDBL_MIN__
     61 
     62 	/* Needed for libjava building - Victor K. */
     63 
     64 	/* Radix of exponent representation, b. */
     65     #undef FLT_RADIX
     66     #define FLT_RADIX	__FLT_RADIX__
     67 
     68     /* Minimum int x such that FLT_RADIX**(x-1) is a normalized float, emin */
     69 	#undef FLT_MIN_EXP
     70 	#undef DBL_MIN_EXP
     71 	#undef LDBL_MIN_EXP
     72 	#define FLT_MIN_EXP	__FLT_MIN_EXP__
     73 	#define DBL_MIN_EXP	__DBL_MIN_EXP__
     74 	#define LDBL_MIN_EXP	__LDBL_MIN_EXP__
     75 
     76 	/* Minimum negative integer such that 10 raised to that power is in the
     77    	range of normalized floating-point numbers,
     78 
     79 	ceil(log10(b) * (emin - 1))
     80 	*/
     81 	#undef FLT_MIN_10_EXP
     82 	#undef DBL_MIN_10_EXP
     83 	#undef LDBL_MIN_10_EXP
     84 	#define FLT_MIN_10_EXP	__FLT_MIN_10_EXP__
     85 	#define DBL_MIN_10_EXP	__DBL_MIN_10_EXP__
     86 	#define LDBL_MIN_10_EXP	__LDBL_MIN_10_EXP__
     87 
     88 	/* Maximum int x such that FLT_RADIX**(x-1) is a representable float, emax.  */
     89 	#undef FLT_MAX_EXP
     90 	#undef DBL_MAX_EXP
     91 	#undef LDBL_MAX_EXP
     92 	#define FLT_MAX_EXP	__FLT_MAX_EXP__
     93 	#define DBL_MAX_EXP	__DBL_MAX_EXP__
     94 	#define LDBL_MAX_EXP	__LDBL_MAX_EXP__
     95 
     96 	/* Maximum integer such that 10 raised to that power is in the range of
     97    	representable finite floating-point numbers,
     98 
     99 	floor(log10((1 - b**-p) * b**emax))
    100 	*/
    101 	#undef FLT_MAX_10_EXP
    102 	#undef DBL_MAX_10_EXP
    103 	#undef LDBL_MAX_10_EXP
    104 	#define FLT_MAX_10_EXP	__FLT_MAX_10_EXP__
    105 	#define DBL_MAX_10_EXP	__DBL_MAX_10_EXP__
    106 	#define LDBL_MAX_10_EXP	__LDBL_MAX_10_EXP__
    107 
    108 	/* Addition rounds to 0: zero, 1: nearest, 2: +inf, 3: -inf, -1: unknown.  */
    109 	/* ??? This is supposed to change with calls to fesetround in <fenv.h>.  */
    110 	#undef FLT_ROUNDS
    111 	#define FLT_ROUNDS 1
    112 
    113 	#define _FLOAT_H___
    114 #endif
    115 #endif
    116 #endif
    117 
    118 #ifndef _MINGW_FLOAT_H_
    119 #define _MINGW_FLOAT_H_
    120 
    121 /* All the headers include this file. */
    122 #include <crtdefs.h>
    123 
    124 /*
    125  * Functions and definitions for controlling the FPU.
    126  */
    127 #ifndef	__STRICT_ANSI__
    128 
    129 /* TODO: These constants are only valid for x86 machines */
    130 
    131 /* Control word masks for unMask */
    132 #define	_MCW_DN  	0x03000000  	/* Denormal control */
    133 #define	_MCW_EM		0x0008001F	/* Error masks */
    134 #define	_MCW_IC		0x00040000	/* Infinity */
    135 #define	_MCW_RC		0x00000300	/* Rounding */
    136 #define	_MCW_PC		0x00030000	/* Precision */
    137 
    138 /* Number of base-FLT_RADIX digits in the significand, p.  */
    139 #undef FLT_MANT_DIG
    140 #undef DBL_MANT_DIG
    141 #undef LDBL_MANT_DIG
    142 #define FLT_MANT_DIG   __FLT_MANT_DIG__
    143 #define DBL_MANT_DIG   __DBL_MANT_DIG__
    144 #define LDBL_MANT_DIG  __LDBL_MANT_DIG__
    145 
    146 #if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    147 /* The floating-point expression evaluation method.
    148       -1  indeterminate
    149        0  evaluate all operations and constants just to the range and
    150 	  precision of the type
    151        1  evaluate operations and constants of type float and double
    152 	  to the range and precision of the double type, evaluate
    153 	  long double operations and constants to the range and
    154 	  precision of the long double type
    155        2  evaluate all operations and constants to the range and
    156 	  precision of the long double type
    157 
    158    ??? This ought to change with the setting of the fp control word;
    159    the value provided by the compiler assumes the widest setting.  */
    160 #undef FLT_EVAL_METHOD
    161 #define FLT_EVAL_METHOD	__FLT_EVAL_METHOD__
    162 
    163 #endif /* C99 */
    164 
    165 
    166 /* Control word values for unNew (use with related unMask above) */
    167 #define	_DN_SAVE	0x00000000
    168 #define	_DN_FLUSH	0x01000000
    169 #define	_EM_INVALID	0x00000010
    170 #define	_EM_DENORMAL	0x00080000
    171 #define	_EM_ZERODIVIDE	0x00000008
    172 #define	_EM_OVERFLOW	0x00000004
    173 #define	_EM_UNDERFLOW	0x00000002
    174 #define	_EM_INEXACT	0x00000001
    175 #define	_IC_AFFINE	0x00040000
    176 #define	_IC_PROJECTIVE	0x00000000
    177 #define	_RC_CHOP	0x00000300
    178 #define	_RC_UP		0x00000200
    179 #define	_RC_DOWN	0x00000100
    180 #define	_RC_NEAR	0x00000000
    181 #define	_PC_24		0x00020000
    182 #define	_PC_53		0x00010000
    183 #define	_PC_64		0x00000000
    184 
    185 /* These are also defined in Mingw math.h, needed to work around
    186    GCC build issues.  */
    187 /* Return values for fpclass. */
    188 #ifndef __MINGW_FPCLASS_DEFINED
    189 #define __MINGW_FPCLASS_DEFINED 1
    190 #define	_FPCLASS_SNAN	0x0001	/* Signaling "Not a Number" */
    191 #define	_FPCLASS_QNAN	0x0002	/* Quiet "Not a Number" */
    192 #define	_FPCLASS_NINF	0x0004	/* Negative Infinity */
    193 #define	_FPCLASS_NN	0x0008	/* Negative Normal */
    194 #define	_FPCLASS_ND	0x0010	/* Negative Denormal */
    195 #define	_FPCLASS_NZ	0x0020	/* Negative Zero */
    196 #define	_FPCLASS_PZ	0x0040	/* Positive Zero */
    197 #define	_FPCLASS_PD	0x0080	/* Positive Denormal */
    198 #define	_FPCLASS_PN	0x0100	/* Positive Normal */
    199 #define	_FPCLASS_PINF	0x0200	/* Positive Infinity */
    200 #endif /* __MINGW_FPCLASS_DEFINED */
    201 
    202 /* invalid subconditions (_SW_INVALID also set) */
    203 #define _SW_UNEMULATED		0x0040  /* unemulated instruction */
    204 #define _SW_SQRTNEG		0x0080  /* square root of a neg number */
    205 #define _SW_STACKOVERFLOW	0x0200  /* FP stack overflow */
    206 #define _SW_STACKUNDERFLOW	0x0400  /* FP stack underflow */
    207 
    208 /*  Floating point error signals and return codes */
    209 #define _FPE_INVALID		0x81
    210 #define _FPE_DENORMAL		0x82
    211 #define _FPE_ZERODIVIDE		0x83
    212 #define _FPE_OVERFLOW		0x84
    213 #define _FPE_UNDERFLOW		0x85
    214 #define _FPE_INEXACT		0x86
    215 #define _FPE_UNEMULATED		0x87
    216 #define _FPE_SQRTNEG		0x88
    217 #define _FPE_STACKOVERFLOW	0x8a
    218 #define _FPE_STACKUNDERFLOW	0x8b
    219 #define _FPE_EXPLICITGEN	0x8c    /* raise( SIGFPE ); */
    220 
    221 #define CW_DEFAULT _CW_DEFAULT
    222 #define MCW_PC  _MCW_PC
    223 #define PC_24   _PC_24
    224 #define PC_53   _PC_53
    225 #define PC_64   _PC_64
    226 
    227 #if defined(_M_IX86)
    228 #define _CW_DEFAULT (_RC_NEAR+_PC_53+_EM_INVALID+_EM_ZERODIVIDE+_EM_OVERFLOW+_EM_UNDERFLOW+_EM_INEXACT+_EM_DENORMAL)
    229 #elif defined(_M_IA64)
    230 #define _CW_DEFAULT (_RC_NEAR+_PC_64+_EM_INVALID+_EM_ZERODIVIDE+_EM_OVERFLOW+_EM_UNDERFLOW+_EM_INEXACT+_EM_DENORMAL)
    231 #elif defined(_M_AMD64)
    232 #define _CW_DEFAULT (_RC_NEAR+_EM_INVALID+_EM_ZERODIVIDE+_EM_OVERFLOW+_EM_UNDERFLOW+_EM_INEXACT+_EM_DENORMAL)
    233 #endif
    234 
    235 #ifndef RC_INVOKED
    236 
    237 #ifdef	__cplusplus
    238 extern "C" {
    239 #endif
    240 
    241 /* Set the FPU control word as cw = (cw & ~unMask) | (unNew & unMask),
    242  * i.e. change the bits in unMask to have the values they have in unNew,
    243  * leaving other bits unchanged. */
    244 _CRTIMP unsigned int __cdecl __MINGW_NOTHROW _controlfp (unsigned int unNew, unsigned int unMask) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
    245 _CRTIMP errno_t __cdecl _controlfp_s(unsigned int *_CurrentState, unsigned int _NewValue, unsigned int _Mask);
    246 _CRTIMP unsigned int __cdecl __MINGW_NOTHROW _control87 (unsigned int unNew, unsigned int unMask);
    247 
    248 
    249 _CRTIMP unsigned int __cdecl __MINGW_NOTHROW _clearfp (void);	/* Clear the FPU status word */
    250 _CRTIMP unsigned int __cdecl __MINGW_NOTHROW _statusfp (void);	/* Report the FPU status word */
    251 #define		_clear87	_clearfp
    252 #define		_status87	_statusfp
    253 
    254 
    255 /*
    256    MSVCRT.dll _fpreset initializes the control register to 0x27f,
    257    the status register to zero and the tag word to 0FFFFh.
    258    This differs from asm instruction finit/fninit which set control
    259    word to 0x37f (64 bit mantissa precison rather than 53 bit).
    260    By default, the mingw version of _fpreset sets fp control as
    261    per fninit. To use the MSVCRT.dll _fpreset, include CRT_fp8.o when
    262    building your application.
    263 */
    264 void __cdecl __MINGW_NOTHROW _fpreset (void);
    265 void __cdecl __MINGW_NOTHROW fpreset (void);
    266 
    267 /* Global 'variable' for the current floating point error code. */
    268 _CRTIMP int * __cdecl __MINGW_NOTHROW __fpecode(void);
    269 #define	_fpecode	(*(__fpecode()))
    270 
    271 /*
    272  * IEEE recommended functions.  MS puts them in float.h
    273  * but they really belong in math.h.
    274  */
    275 
    276 #ifndef _SIGN_DEFINED
    277 #define _SIGN_DEFINED
    278 _CRTIMP double __cdecl __MINGW_NOTHROW _chgsign (double _X);
    279 _CRTIMP double __cdecl __MINGW_NOTHROW _copysign (double _Number,double _Sign);
    280 _CRTIMP double __cdecl __MINGW_NOTHROW _logb (double);
    281 _CRTIMP double __cdecl __MINGW_NOTHROW _nextafter (double, double);
    282 _CRTIMP double __cdecl __MINGW_NOTHROW _scalb (double, long);
    283 
    284 _CRTIMP int __cdecl __MINGW_NOTHROW _finite (double);
    285 _CRTIMP int __cdecl __MINGW_NOTHROW _fpclass (double);
    286 _CRTIMP int __cdecl __MINGW_NOTHROW _isnan (double);
    287 
    288 #define _copysignl copysignl
    289 extern long double __cdecl _chgsignl (long double);
    290 #endif /* _SIGN_DEFINED */
    291 
    292 #ifdef	__cplusplus
    293 }
    294 #endif
    295 
    296 #endif	/* Not RC_INVOKED */
    297 
    298 #endif	/* Not __STRICT_ANSI__ */
    299 
    300 #endif /* _MINGW_FLOAT_H_ */
    301 
    302