diff options
Diffstat (limited to 'lib/pure/fenv.nim')
-rw-r--r-- | lib/pure/fenv.nim | 97 |
1 files changed, 49 insertions, 48 deletions
diff --git a/lib/pure/fenv.nim b/lib/pure/fenv.nim index f8f115ecc..1d96fd6be 100644 --- a/lib/pure/fenv.nim +++ b/lib/pure/fenv.nim @@ -9,10 +9,10 @@ ## Floating-point environment. Handling of floating-point rounding and ## exceptions (overflow, division by zero, etc.). +## The types, vars and procs are bindings for the C standard library +## [<fenv.h>](https://en.cppreference.com/w/c/numeric/fenv) header. -{.deadCodeElim:on.} - -when defined(Posix) and not defined(haiku): +when defined(posix) and not defined(genode) and not defined(macosx): {.passl: "-lm".} var @@ -37,8 +37,8 @@ var FE_UPWARD* {.importc, header: "<fenv.h>".}: cint ## round toward +Inf FE_DFL_ENV* {.importc, header: "<fenv.h>".}: cint - ## macro of type pointer to fenv_t to be used as the argument - ## to functions taking an argument of type fenv_t; in this + ## macro of type pointer to `fenv_t` to be used as the argument + ## to functions taking an argument of type `fenv_t`; in this ## case the default environment will be used type @@ -102,80 +102,81 @@ proc feupdateenv*(envp: ptr Tfenv): cint {.importc, header: "<fenv.h>".} ## represented by object pointed to by `envp` and raise exceptions ## according to saved exceptions. -var FP_RADIX_INTERNAL {. importc: "FLT_RADIX" header: "<float.h>" .} : int - -template fpRadix* : int = FP_RADIX_INTERNAL +const + FLT_RADIX = 2 ## the radix of the exponent representation + + FLT_MANT_DIG = 24 ## the number of base FLT_RADIX digits in the mantissa part of a float + FLT_DIG = 6 ## the number of digits of precision of a float + FLT_MIN_EXP = -125 ## the minimum value of base FLT_RADIX in the exponent part of a float + FLT_MAX_EXP = 128 ## the maximum value of base FLT_RADIX in the exponent part of a float + FLT_MIN_10_EXP = -37 ## the minimum value in base 10 of the exponent part of a float + FLT_MAX_10_EXP = 38 ## the maximum value in base 10 of the exponent part of a float + FLT_MIN = 1.17549435e-38'f32 ## the minimum value of a float + FLT_MAX = 3.40282347e+38'f32 ## the maximum value of a float + FLT_EPSILON = 1.19209290e-07'f32 ## the difference between 1 and the least value greater than 1 of a float + + DBL_MANT_DIG = 53 ## the number of base FLT_RADIX digits in the mantissa part of a double + DBL_DIG = 15 ## the number of digits of precision of a double + DBL_MIN_EXP = -1021 ## the minimum value of base FLT_RADIX in the exponent part of a double + DBL_MAX_EXP = 1024 ## the maximum value of base FLT_RADIX in the exponent part of a double + DBL_MIN_10_EXP = -307 ## the minimum value in base 10 of the exponent part of a double + DBL_MAX_10_EXP = 308 ## the maximum value in base 10 of the exponent part of a double + DBL_MIN = 2.2250738585072014E-308 ## the minimal value of a double + DBL_MAX = 1.7976931348623157E+308 ## the minimal value of a double + DBL_EPSILON = 2.2204460492503131E-16 ## the difference between 1 and the least value greater than 1 of a double + +template fpRadix*: int = FLT_RADIX ## The (integer) value of the radix used to represent any floating ## point type on the architecture used to build the program. -var FLT_MANT_DIG {. importc: "FLT_MANT_DIG" header: "<float.h>" .} : int -var FLT_DIG {. importc: "FLT_DIG" header: "<float.h>" .} : int -var FLT_MIN_EXP {. importc: "FLT_MIN_EXP" header: "<float.h>" .} : int -var FLT_MAX_EXP {. importc: "FLT_MAX_EXP" header: "<float.h>" .} : int -var FLT_MIN_10_EXP {. importc: "FLT_MIN_10_EXP" header: "<float.h>" .} : int -var FLT_MAX_10_EXP {. importc: "FLT_MAX_10_EXP" header: "<float.h>" .} : int -var FLT_MIN {. importc: "FLT_MIN" header: "<float.h>" .} : cfloat -var FLT_MAX {. importc: "FLT_MAX" header: "<float.h>" .} : cfloat -var FLT_EPSILON {. importc: "FLT_EPSILON" header: "<float.h>" .} : cfloat - -var DBL_MANT_DIG {. importc: "DBL_MANT_DIG" header: "<float.h>" .} : int -var DBL_DIG {. importc: "DBL_DIG" header: "<float.h>" .} : int -var DBL_MIN_EXP {. importc: "DBL_MIN_EXP" header: "<float.h>" .} : int -var DBL_MAX_EXP {. importc: "DBL_MAX_EXP" header: "<float.h>" .} : int -var DBL_MIN_10_EXP {. importc: "DBL_MIN_10_EXP" header: "<float.h>" .} : int -var DBL_MAX_10_EXP {. importc: "DBL_MAX_10_EXP" header: "<float.h>" .} : int -var DBL_MIN {. importc: "DBL_MIN" header: "<float.h>" .} : cdouble -var DBL_MAX {. importc: "DBL_MAX" header: "<float.h>" .} : cdouble -var DBL_EPSILON {. importc: "DBL_EPSILON" header: "<float.h>" .} : cdouble - -template mantissaDigits*(T : typedesc[float32]) : int = FLT_MANT_DIG - ## Number of digits (in base ``floatingPointRadix``) in the mantissa +template mantissaDigits*(T: typedesc[float32]): int = FLT_MANT_DIG + ## Number of digits (in base `floatingPointRadix`) in the mantissa ## of 32-bit floating-point numbers. -template digits*(T : typedesc[float32]) : int = FLT_DIG +template digits*(T: typedesc[float32]): int = FLT_DIG ## Number of decimal digits that can be represented in a ## 32-bit floating-point type without losing precision. -template minExponent*(T : typedesc[float32]) : int = FLT_MIN_EXP +template minExponent*(T: typedesc[float32]): int = FLT_MIN_EXP ## Minimum (negative) exponent for 32-bit floating-point numbers. -template maxExponent*(T : typedesc[float32]) : int = FLT_MAX_EXP +template maxExponent*(T: typedesc[float32]): int = FLT_MAX_EXP ## Maximum (positive) exponent for 32-bit floating-point numbers. -template min10Exponent*(T : typedesc[float32]) : int = FLT_MIN_10_EXP +template min10Exponent*(T: typedesc[float32]): int = FLT_MIN_10_EXP ## Minimum (negative) exponent in base 10 for 32-bit floating-point ## numbers. -template max10Exponent*(T : typedesc[float32]) : int = FLT_MAX_10_EXP +template max10Exponent*(T: typedesc[float32]): int = FLT_MAX_10_EXP ## Maximum (positive) exponent in base 10 for 32-bit floating-point ## numbers. -template minimumPositiveValue*(T : typedesc[float32]) : float32 = FLT_MIN +template minimumPositiveValue*(T: typedesc[float32]): float32 = FLT_MIN ## The smallest positive (nonzero) number that can be represented in a ## 32-bit floating-point type. -template maximumPositiveValue*(T : typedesc[float32]) : float32 = FLT_MAX +template maximumPositiveValue*(T: typedesc[float32]): float32 = FLT_MAX ## The largest positive number that can be represented in a 32-bit ## floating-point type. -template epsilon*(T : typedesc[float32]): float32 = FLT_EPSILON +template epsilon*(T: typedesc[float32]): float32 = FLT_EPSILON ## The difference between 1.0 and the smallest number greater than ## 1.0 that can be represented in a 32-bit floating-point type. -template mantissaDigits*(T : typedesc[float64]) : int = DBL_MANT_DIG - ## Number of digits (in base ``floatingPointRadix``) in the mantissa +template mantissaDigits*(T: typedesc[float64]): int = DBL_MANT_DIG + ## Number of digits (in base `floatingPointRadix`) in the mantissa ## of 64-bit floating-point numbers. -template digits*(T : typedesc[float64]) : int = DBL_DIG +template digits*(T: typedesc[float64]): int = DBL_DIG ## Number of decimal digits that can be represented in a ## 64-bit floating-point type without losing precision. -template minExponent*(T : typedesc[float64]) : int = DBL_MIN_EXP +template minExponent*(T: typedesc[float64]): int = DBL_MIN_EXP ## Minimum (negative) exponent for 64-bit floating-point numbers. -template maxExponent*(T : typedesc[float64]) : int = DBL_MAX_EXP +template maxExponent*(T: typedesc[float64]): int = DBL_MAX_EXP ## Maximum (positive) exponent for 64-bit floating-point numbers. -template min10Exponent*(T : typedesc[float64]) : int = DBL_MIN_10_EXP +template min10Exponent*(T: typedesc[float64]): int = DBL_MIN_10_EXP ## Minimum (negative) exponent in base 10 for 64-bit floating-point ## numbers. -template max10Exponent*(T : typedesc[float64]) : int = DBL_MAX_10_EXP +template max10Exponent*(T: typedesc[float64]): int = DBL_MAX_10_EXP ## Maximum (positive) exponent in base 10 for 64-bit floating-point ## numbers. -template minimumPositiveValue*(T : typedesc[float64]) : float64 = DBL_MIN +template minimumPositiveValue*(T: typedesc[float64]): float64 = DBL_MIN ## The smallest positive (nonzero) number that can be represented in a ## 64-bit floating-point type. -template maximumPositiveValue*(T : typedesc[float64]) : float64 = DBL_MAX +template maximumPositiveValue*(T: typedesc[float64]): float64 = DBL_MAX ## The largest positive number that can be represented in a 64-bit ## floating-point type. -template epsilon*(T : typedesc[float64]): float64 = DBL_EPSILON +template epsilon*(T: typedesc[float64]): float64 = DBL_EPSILON ## The difference between 1.0 and the smallest number greater than ## 1.0 that can be represented in a 64-bit floating-point type. |