From bf7c34242697304157de2f72d1dec8c051ede4b5 Mon Sep 17 00:00:00 2001 From: Maurizio Tomasi Date: Thu, 5 Mar 2015 15:04:39 +0100 Subject: New templates for getting the limits of FP types added. New variable "FP_RADIX" and new templates "mantissaDigits", "digits", "minExponent", "maxExponent", "min10Exponent", "max10Exponent", "minimumPositiveValue", "maximumPositiveValue", and "epsilon" added to retrieve the limits of floating-point types. --- lib/pure/fenv.nim | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/lib/pure/fenv.nim b/lib/pure/fenv.nim index 6f9085c92..f64358d38 100644 --- a/lib/pure/fenv.nim +++ b/lib/pure/fenv.nim @@ -101,3 +101,79 @@ proc feupdateenv*(envp: ptr Tfenv): cint {.importc, header: "".} ## Save current exceptions in temporary storage, install environment ## represented by object pointed to by `envp` and raise exceptions ## according to saved exceptions. + +var FP_RADIX* {. importc: "FLT_RADIX" header: "" .} : int + ## 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: "" .} : int +var FLT_DIG {. importc: "FLT_DIG" header: "" .} : int +var FLT_MIN_EXP {. importc: "FLT_MIN_EXP" header: "" .} : int +var FLT_MAX_EXP {. importc: "FLT_MAX_EXP" header: "" .} : int +var FLT_MIN_10_EXP {. importc: "FLT_MIN_10_EXP" header: "" .} : int +var FLT_MAX_10_EXP {. importc: "FLT_MAX_10_EXP" header: "" .} : int +var FLT_MIN {. importc: "FLT_MIN" header: "" .} : cfloat +var FLT_MAX {. importc: "FLT_MAX" header: "" .} : cfloat +var FLT_EPSILON {. importc: "FLT_EPSILON" header: "" .} : cfloat + +var DBL_MANT_DIG {. importc: "DBL_MANT_DIG" header: "" .} : int +var DBL_DIG {. importc: "DBL_DIG" header: "" .} : int +var DBL_MIN_EXP {. importc: "DBL_MIN_EXP" header: "" .} : int +var DBL_MAX_EXP {. importc: "DBL_MAX_EXP" header: "" .} : int +var DBL_MIN_10_EXP {. importc: "DBL_MIN_10_EXP" header: "" .} : int +var DBL_MAX_10_EXP {. importc: "DBL_MAX_10_EXP" header: "" .} : int +var DBL_MIN {. importc: "DBL_MIN" header: "" .} : cdouble +var DBL_MAX {. importc: "DBL_MAX" header: "" .} : cdouble +var DBL_EPSILON {. importc: "DBL_EPSILON" header: "" .} : cdouble + +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 + ## Number of decimal digits that can be represented for the + ## 32-bit floating-point type without losing precision. +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 + ## Maximum (positive) exponent for 32-bit floating-point numbers. +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 + ## Maximum (positive) exponent in base 10 for 32-bit floating-point + ## numbers. +template minimumPositiveValue*(T : typedesc[float32]) : float32 = FLT_MIN + ## The smallest positive (nonzero) number that can be hold by a + ## 32-bit floating-point type. +template maximumPositiveValue*(T : typedesc[float32]) : float32 = FLT_MAX + ## The largest positive number that can be hold by a 32-bit + ## floating-point type. +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 using a 32-bit floating-point type. + +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 + ## Number of decimal digits that can be represented for the + ## 64-bit floating-point type without losing precision. +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 + ## Maximum (positive) exponent for 64-bit floating-point numbers. +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 + ## Maximum (positive) exponent in base 10 for 64-bit floating-point + ## numbers. +template minimumPositiveValue*(T : typedesc[float64]) : float64 = DBL_MIN + ## The smallest positive (nonzero) number that can be hold by a + ## 64-bit floating-point type. +template maximumPositiveValue*(T : typedesc[float64]) : float64 = DBL_MAX + ## The largest positive number that can be hold by a 64-bit + ## floating-point type. +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 using a 64-bit floating-point type. -- cgit 1.4.1-2-gfad0