' ########################################################################################
' Microsoft C Runtime
' File: float.inc
' Contents: This file contains defines for a number of implementation dependent values
' which are commonly used by sophisticated numerical (floating point) programs. [ANSI]
' Copyright (c) 2011 Jos? Roca
' Portions Copyright (c) Microsoft Corporation.
' All Rights Reserved.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################
#IF NOT %DEF(PBX_float_PBI)
#DEFINE PBX_float_PBI
%EQUATE `FLOAT_INC = 1
#INCLUDE ONCE "Legacy/Runtime/crtdefs.inc"
%EQUATE `DBL_DIG = 15 ' /* # of decimal digits of precision */
MACRO DBL_EPSILON = 2.2204460492503131e-016 ' /* smallest such that 1.0+DBL_EPSILON != 1.0 */
%EQUATE `DBL_MANT_DIG = 53 ' /* # of bits in mantissa */
MACRO DBL_MAX = 1.7976931348623158e+308 ' /* max value */
%EQUATE `DBL_MAX_10_EXP = 308 ' /* max decimal exponent */
%EQUATE `DBL_MAX_EXP = 1024 ' /* max binary exponent */
MACRO DBL_MIN = 2.2250738585072014e-308 ' /* min positive value */
%EQUATE `DBL_MIN_10_EXP = -307 ' /* min decimal exponent */
%EQUATE `DBL_MIN_EXP = -1021 ' /* min binary exponent */
%EQUATE `DBL_RADIX = 2 ' /* exponent radix */
%EQUATE `DBL_ROUNDS = 1 ' /* addition rounding: near */
%EQUATE `FLT_DIG = 6 ' /* # of decimal digits of precision */
MACRO FLT_EPSILON = 1.192092896e-07 ' /* smallest such that 1.0+FLT_EPSILON != 1.0 */
%EQUATE `FLT_GUARD = 0
%EQUATE `FLT_MANT_DIG = 24 ' /* # of bits in mantissa */
MACRO FLT_MAX = 3.402823466e+38 ' /* max value */
%EQUATE `FLT_MAX_10_EXP = 38 ' /* max decimal exponent */
%EQUATE `FLT_MAX_EXP = 128 ' /* max binary exponent */
MACRO FLT_MIN = 1.175494351e-38 ' /* min positive value */
%EQUATE `FLT_MIN_10_EXP = -37 ' /* min decimal exponent */
%EQUATE `FLT_MIN_EXP = -125 ' /* min binary exponent */
%EQUATE `FLT_NORMALIZE = 0
%EQUATE `FLT_RADIX = 2 ' /* exponent radix */
%EQUATE `FLT_ROUNDS = 1 ' /* addition rounding: near */
%EQUATE `LDBL_DIG = %DBL_DIG ' /* # of decimal digits of precision */
MACRO LDBL_EPSILON = DBL_EPSILON ' /* smallest such that 1.0+L= %DBL_EPSILON != 1.0 */
%EQUATE `LDBL_MANT_DIG = %DBL_MANT_DIG ' /* # of bits in mantissa */
MACRO LDBL_MAX = DBL_MAX ' /* max value */
%EQUATE `LDBL_MAX_10_EXP = %DBL_MAX_10_EXP ' /* max decimal exponent */
%EQUATE `LDBL_MAX_EXP = %DBL_MAX_EXP ' /* max binary exponent */
MACRO LDBL_MIN = DBL_MIN ' /* min positive value */
%EQUATE `LDBL_MIN_10_EXP = %DBL_MIN_10_EXP ' /* min decimal exponent */
%EQUATE `LDBL_MIN_EXP = %DBL_MIN_EXP ' /* min binary exponent */
%EQUATE `LDBL_RADIX = %DBL_RADIX ' /* exponent radix */
%EQUATE `LDBL_ROUNDS = %DBL_ROUNDS ' /* addition rounding: near */
'/* Function prototypes */
'/* Reading or writing the floating point control/status words is not supported in managed code */
' ========================================================================================
' *** All versions ***
' _CRT_MANAGED_FP_DEPRECATE _CRTIMP unsigned int __cdecl _clearfp(void);
' ========================================================================================
DECLARE FUNCTION clearfp_ CDECL IMPORT $CRT_DLLNAME ALIAS "_clearfp" ( ) AS QUAD ' unsigned int
' ========================================================================================
' ========================================================================================
' *** All versions ***
' _CRT_MANAGED_FP_DEPRECATE _CRT_INSECURE_DEPRECATE(_controlfp_s)
' _CRTIMP unsigned int __cdecl _controlfp(_In_ unsigned int _NewValue,_In_ unsigned int _Mask);
' ========================================================================================
DECLARE FUNCTION controlfp_ CDECL IMPORT $CRT_DLLNAME ALIAS "_controlfp" ( BYVAL new AS QUAD , BYVAL mask AS QUAD ) AS QUAD
' ========================================================================================
' ========================================================================================
' _CRT_MANAGED_FP_DEPRECATE _CRTIMP void __cdecl _set_controlfp(
'_In_ unsigned int _NewValue, _In_ unsigned int _Mask);
' ========================================================================================
DECLARE SUB set_controlfp CDECL IMPORT $CRT_DLLNAME ALIAS "_set_controlfp" ( BYVAL newControl AS QUAD , BYVAL mask AS QUAD ) ' void
' ========================================================================================
' ========================================================================================
' _CRT_MANAGED_FP_DEPRECATE _CRTIMP errno_t __cdecl _controlfp_s(
' _Out_opt_ unsigned int *_CurrentState, _In_ unsigned int _NewValue, _In_ unsigned int _Mask);
' ========================================================================================
DECLARE FUNCTION controlfp_s CDECL IMPORT $CRT_DLLNAME ALIAS "_controlfp_s" ( BYVAL currentControl AS QUAD , BYVAL newControl AS QUAD , BYVAL mask AS QUAD ) AS LONG ' errno_t
' ========================================================================================
' ========================================================================================
' *** All versions ***
' _CRT_MANAGED_FP_DEPRECATE _CRTIMP unsigned int __cdecl _statusfp(void);
' ========================================================================================
DECLARE FUNCTION statusfp_ CDECL IMPORT $CRT_DLLNAME ALIAS "_statusfp" ( ) AS QUAD ' unsigned int
' ========================================================================================
' ========================================================================================
' *** All versions ***
' _CRT_MANAGED_FP_DEPRECATE _CRTIMP void __cdecl _fpreset(void);
' ========================================================================================
DECLARE SUB fpreset_ CDECL IMPORT $CRT_DLLNAME ALIAS "_fpreset" ()
' ========================================================================================
'/*
' * Abstract User Status Word bit definitions
' */
%EQUATE `SW_INEXACT = &H00000001 ' /* inexact (precision) */
%EQUATE `SW_UNDERFLOW = &H00000002 ' /* underflow */
%EQUATE `SW_OVERFLOW = &H00000004 ' /* overflow */
%EQUATE `SW_ZERODIVIDE = &H00000008 ' /* zero divide */
%EQUATE `SW_INVALID = &H00000010 ' /* invalid */
%EQUATE `SW_DENORMAL = &H00080000 ' /* denormal status bit */
'/*
' * New Control Bit that specifies the ambiguity in control word.
' */
%EQUATE `EM_AMBIGUIOUS = &H80000000 ' /* for backwards compatibility old spelling */
%EQUATE `EM_AMBIGUOUS = &H80000000
'/*
' * Abstract User Control Word Mask and bit definitions
' */
%EQUATE `MCW_EM = &H0008001f ' /* interrupt Exception Masks */
%EQUATE `EM_INEXACT = &H00000001 ' /* inexact (precision) */
%EQUATE `EM_UNDERFLOW = &H00000002 ' /* underflow */
%EQUATE `EM_OVERFLOW = &H00000004 ' /* overflow */
%EQUATE `EM_ZERODIVIDE = &H00000008 ' /* zero divide */
%EQUATE `EM_INVALID = &H00000010 ' /* invalid */
%EQUATE `EM_DENORMAL = &H00080000 ' /* denormal exception mask (_control87 only) */
%EQUATE `MCW_RC = &H00000300 ' /* Rounding Control */
%EQUATE `RC_NEAR = &H00000000 ' /* near */
%EQUATE `RC_DOWN = &H00000100 ' /* down */
%EQUATE `RC_UP = &H00000200 ' /* up */
%EQUATE `RC_CHOP = &H00000300 ' /* chop */
'/*
' * i386 specific definitions
' */
%EQUATE `MCW_PC = &H00030000 ' /* Precision Control */
%EQUATE `PC_64 = &H00000000 ' /* 64 bits */
%EQUATE `PC_53 = &H00010000 ' /* 53 bits */
%EQUATE `PC_24 = &H00020000 ' /* 24 bits */
%EQUATE `MCW_IC = &H00040000 ' /* Infinity Control */
%EQUATE `IC_AFFINE = &H00040000 ' /* affine */
%EQUATE `IC_PROJECTIVE = &H00000000 ' /* projective */
'/*
' * RISC specific definitions
' */
%EQUATE `MCW_DN = &H03000000 ' /* Denormal Control */
%EQUATE `DN_SAVE = &H00000000 ' /* save denormal results and operands */
%EQUATE `DN_FLUSH = &H01000000 ' /* flush denormal results and operands to zero */
%EQUATE `DN_FLUSH_OPERANDS_SAVE_RESULTS = &H02000000 ' /* flush operands to zero and save results */
%EQUATE `DN_SAVE_OPERANDS_FLUSH_RESULTS = &H03000000 ' /* save operands and flush results to zero */
'/* initial Control Word value */
%EQUATE `CW_DEFAULT = %RC_NEAR + %PC_53 + %EM_INVALID + %EM_ZERODIVIDE + %EM_OVERFLOW + %EM_UNDERFLOW + %EM_INEXACT + %EM_DENORMAL
' ========================================================================================
' *** All versions ***
' _CRT_MANAGED_FP_DEPRECATE _CRTIMP unsigned int __cdecl _control87(
' _In_ unsigned int _NewValue,_In_ unsigned int _Mask);
' ========================================================================================
DECLARE FUNCTION control87_ CDECL IMPORT $CRT_DLLNAME ALIAS "_control87" ( BYVAL new AS QUAD , BYVAL mask AS QUAD ) AS QUAD ' unsigned int
' ========================================================================================
'/* Global variable holding floating point error code */
'#if defined(_MT) || defined(_DLL)
'_Check_return_ _CRTIMP extern int * __cdecl __fpecode(void);
'#define _fpecode (*__fpecode())
'#else /* ndef _MT && ndef _DLL */
'extern int _fpecode;
'#endif /* _MT || _DLL */
' *** All versions ***
FUNCTION get_fpecode CDECL () AS LONG
 LOCAL hLib AS DWORD
 LOCAL pfpecode AS LONG PTR
 hLib = LoadLibrary($CRT_DLLNAME)
 IF hLib THEN
 pfpecode = GetProcAddress(hLib, "__fpecode")
 IF pfpecode THEN FUNCTION = @pfpecode
 FreeLibrary hLib
 END IF
END FUNCTION
'/* invalid subconditions (_SW_INVALID also set) */
%EQUATE `SW_UNEMULATED = &H0040 ' /* unemulated instruction */
%EQUATE `SW_SQRTNEG = &H0080 ' /* square root of a neg number */
%EQUATE `SW_STACKOVERFLOW = &H0200 ' /* FP stack overflow */
%EQUATE `SW_STACKUNDERFLOW = &H0400 ' /* FP stack underflow */
'/* Floating point error signals and return codes */
%EQUATE `FPE_INVALID = &H81&
%EQUATE `FPE_DENORMAL = &H82&
%EQUATE `FPE_ZERODIVIDE = &H83&
%EQUATE `FPE_OVERFLOW = &H84&
%EQUATE `FPE_UNDERFLOW = &H85&
%EQUATE `FPE_INEXACT = &H86&
%EQUATE `FPE_UNEMULATED = &H87&
%EQUATE `FPE_SQRTNEG = &H88&
%EQUATE `FPE_STACKOVERFLOW = &H8a&
%EQUATE `FPE_STACKUNDERFLOW = &H8b&
%EQUATE `FPE_EXPLICITGEN = &H8c& ' /* raise( SIGFPE ); */
'/* IEEE recommended functions */
#IF NOT %DEF(%SIGN_DEFINED)
 %SIGN_DEFINED = 1
' ========================================================================================
' *** All versions ***
' _Check_return_ _CRTIMP double __cdecl _copysign (_In_ double _Number, _In_ double _Sign);
' ========================================================================================
DECLARE FUNCTION copysign_ CDECL IMPORT $CRT_DLLNAME ALIAS "_copysign" ( BYVAL x AS DOUBLE , BYVAL y AS DOUBLE ) AS DOUBLE ' double
' ========================================================================================
' ========================================================================================
' *** All versions ***
' _Check_return_ _CRTIMP double __cdecl _chgsign (_In_ double _X);
' ========================================================================================
DECLARE FUNCTION chgsign_ CDECL IMPORT $CRT_DLLNAME ALIAS "_chgsign" ( BYVAL x AS DOUBLE ) AS DOUBLE ' double
' ========================================================================================
#ENDIF ' SIGN_DEFINED
' ========================================================================================
' *** All versions ***
' _Check_return_ _CRTIMP double __cdecl _scalb(_In_ double _X, _In_ long _Y);
' ========================================================================================
DECLARE FUNCTION scalb_ CDECL IMPORT $CRT_DLLNAME ALIAS "_scalb" ( BYVAL x AS DOUBLE , BYVAL exp AS LONG ) AS DOUBLE ' double
' ========================================================================================
' ========================================================================================
' *** All versions ***
' _Check_return_ _CRTIMP double __cdecl _logb(_In_ double _X);
' ========================================================================================
DECLARE FUNCTION logb_ CDECL IMPORT $CRT_DLLNAME ALIAS "_logb" ( BYVAL x AS DOUBLE ) AS DOUBLE ' double
' ========================================================================================
' ========================================================================================
' *** All versions ***
' _Check_return_ _CRTIMP double __cdecl _nextafter(_In_ double _X, _In_ double _Y);
' ========================================================================================
DECLARE FUNCTION nextafter_ CDECL IMPORT $CRT_DLLNAME ALIAS "_nextafter" ( BYVAL x AS DOUBLE , BYVAL y AS DOUBLE ) AS DOUBLE ' double
' ========================================================================================
' ========================================================================================
' *** All versions ***
' _Check_return_ _CRTIMP int __cdecl _finite(_In_ double _X);
' ========================================================================================
DECLARE FUNCTION finite_ CDECL IMPORT $CRT_DLLNAME ALIAS "_finite" ( BYVAL x AS DOUBLE ) AS LONG ' int
' ========================================================================================
' ========================================================================================
' *** All versions ***
' _Check_return_ _CRTIMP int __cdecl _isnan(_In_ double _X);
' ========================================================================================
DECLARE FUNCTION isnan_ CDECL IMPORT $CRT_DLLNAME ALIAS "_isnan" ( BYVAL x AS DOUBLE ) AS LONG ' int
' ========================================================================================
' ========================================================================================
' *** All versions ***
' _Check_return_ _CRTIMP int __cdecl _fpclass(_In_ double _X);
' ========================================================================================
DECLARE FUNCTION fpclass_ CDECL IMPORT $CRT_DLLNAME ALIAS "_fpclass" ( BYVAL x AS DOUBLE ) AS LONG ' int
' ========================================================================================
%EQUATE `FPCLASS_SNAN = &H0001& ' /* signaling NaN */
%EQUATE `FPCLASS_QNAN = &H0002& ' /* quiet NaN */
%EQUATE `FPCLASS_NINF = &H0004& ' /* negative infinity */
%EQUATE `FPCLASS_NN = &H0008& ' /* negative normal */
%EQUATE `FPCLASS_ND = &H0010& ' /* negative denormal */
%EQUATE `FPCLASS_NZ = &H0020& ' /* -0 */
%EQUATE `FPCLASS_PZ = &H0040& ' /* +0 */
%EQUATE `FPCLASS_PD = &H0080& ' /* positive denormal */
%EQUATE `FPCLASS_PN = &H0100& ' /* positive normal */
%EQUATE `FPCLASS_PINF = &H0200& ' /* positive infinity */
#ENDIF
