diff --git a/lib/impure/fenv.nim b/lib/impure/fenv.nim new file mode 100644 index 0000000000..9d7c8809b9 --- /dev/null +++ b/lib/impure/fenv.nim @@ -0,0 +1,113 @@ +# +# +# Nimrod's Runtime Library +# (c) Copyright 2014 Andreas Rumpf +# +# See the file "copying.txt", included in this +# distribution, for details about the copyright. +# + +## Floating-point environment. Handling of floating-point rounding and +## exceptions (overflow, zero-devide, etc.). + +{.deadCodeElim:on.} + +when defined(Posix) and not defined(haiku): + {.passl: "-lm".} + +var + FE_DIVBYZERO* {.importc, header: "".}: cint + ## division by zero + FE_INEXACT* {.importc, header: "".}: cint + ## inexact result + FE_INVALID* {.importc, header: "".}: cint + ## invalid operation + FE_OVERFLOW* {.importc, header: "".}: cint + ## result not representable due to overflow + FE_UNDERFLOW* {.importc, header: "".}: cint + ## result not representable due to underflow + FE_ALL_EXCEPT* {.importc, header: "".}: cint + ## bitwise OR of all supported exceptions + FE_DOWNWARD* {.importc, header: "".}: cint + ## round toward -Inf + FE_TONEAREST* {.importc, header: "".}: cint + ## round to nearest + FE_TOWARDZERO* {.importc, header: "".}: cint + ## round toward 0 + FE_UPWARD* {.importc, header: "".}: cint + ## round toward +Inf + FE_DFL_ENV* {.importc, header: "".}: 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 + ## case the default environment will be used + +type + TFloatClass* = enum ## describes the class a floating point value belongs to. + ## This is the type that is returned by `classify`. + fcNormal, ## value is an ordinary nonzero floating point value + fcSubnormal, ## value is a subnormal (a very small) floating point value + fcZero, ## value is zero + fcNegZero, ## value is the negative zero + fcNan, ## value is Not-A-Number (NAN) + fcInf, ## value is positive infinity + fcNegInf ## value is negative infinity + + Tfenv* {.importc: "fenv_t", header: "", final, pure.} = + object ## Represents the entire floating-point environment. The + ## floating-point environment refers collectively to any + ## floating-point status flags and control modes supported + ## by the implementation. + Tfexcept* {.importc: "fexcept_t", header: "", final, pure.} = + object ## Represents the floating-point status flags collectively, + ## including any status the implementation associates with the + ## flags. A floating-point status flag is a system variable + ## whose value is set (but never cleared) when a floating-point + ## exception is raised, which occurs as a side effect of + ## exceptional floating-point arithmetic to provide auxiliary + ## information. A floating-point control mode is a system variable + ## whose value may be set by the user to affect the subsequent + ## behavior of floating-point arithmetic. + +proc feclearexcept*(excepts: cint): cint {.importc, header: "".} + ## Clear the supported exceptions represented by `excepts`. + +proc fegetexceptflag*(flagp: ptr Tfexcept, excepts: cint): cint {. + importc, header: "".} + ## Store implementation-defined representation of the exception flags + ## indicated by `excepts` in the object pointed to by `flagp`. + +proc feraiseexcept*(excepts: cint): cint {.importc, header: "".} + ## Raise the supported exceptions represented by `excepts`. + +proc fesetexceptflag*(flagp: ptr Tfexcept, excepts: cint): cint {. + importc, header: "".} + ## Set complete status for exceptions indicated by `excepts` according to + ## the representation in the object pointed to by `flagp`. + +proc fetestexcept*(excepts: cint): cint {.importc, header: "".} + ## Determine which of subset of the exceptions specified by `excepts` are + ## currently set. + +proc fegetround*(): cint {.importc, header: "".} + ## Get current rounding direction. + +proc fesetround*(roundingDirection: cint): cint {.importc, header: "".} + ## Establish the rounding direction represented by `roundingDirection`. + +proc fegetenv*(envp: ptr Tfenv): cint {.importc, header: "".} + ## Store the current floating-point environment in the object pointed + ## to by `envp`. + +proc feholdexcept*(envp: ptr Tfenv): cint {.importc, header: "".} + ## Save the current environment in the object pointed to by `envp`, clear + ## exception flags and install a non-stop mode (if available) for all + ## exceptions. + +proc fesetenv*(a1: ptr Tfenv): cint {.importc, header: "".} + ## Establish the floating-point environment represented by the object + ## pointed to by `envp`. + +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. diff --git a/lib/posix/posix.nim b/lib/posix/posix.nim index e1bcd9dfcb..9334ceeae0 100644 --- a/lib/posix/posix.nim +++ b/lib/posix/posix.nim @@ -99,22 +99,6 @@ type l_pid*: TPid ## Process ID of the process holding the lock; ## returned with F_GETLK. - Tfenv* {.importc: "fenv_t", header: "", final, pure.} = - object ## Represents the entire floating-point environment. The - ## floating-point environment refers collectively to any - ## floating-point status flags and control modes supported - ## by the implementation. - Tfexcept* {.importc: "fexcept_t", header: "", final, pure.} = - object ## Represents the floating-point status flags collectively, - ## including any status the implementation associates with the - ## flags. A floating-point status flag is a system variable - ## whose value is set (but never cleared) when a floating-point - ## exception is raised, which occurs as a side effect of - ## exceptional floating-point arithmetic to provide auxiliary - ## information. A floating-point control mode is a system variable - ## whose value may be set by the user to affect the subsequent - ## behavior of floating-point arithmetic. - TFTW* {.importc: "struct FTW", header: "", final, pure.} = object base*: cint level*: cint @@ -834,18 +818,6 @@ var ## The application expects to access the specified data once and ## then not reuse it thereafter. - FE_DIVBYZERO* {.importc, header: "".}: cint - FE_INEXACT* {.importc, header: "".}: cint - FE_INVALID* {.importc, header: "".}: cint - FE_OVERFLOW* {.importc, header: "".}: cint - FE_UNDERFLOW* {.importc, header: "".}: cint - FE_ALL_EXCEPT* {.importc, header: "".}: cint - FE_DOWNWARD* {.importc, header: "".}: cint - FE_TONEAREST* {.importc, header: "".}: cint - FE_TOWARDZERO* {.importc, header: "".}: cint - FE_UPWARD* {.importc, header: "".}: cint - FE_DFL_ENV* {.importc, header: "".}: cint - when not defined(haiku) and not defined(OpenBSD): var MM_HARD* {.importc, header: "".}: cint @@ -1821,20 +1793,6 @@ proc posix_fadvise*(a1: cint, a2, a3: TOff, a4: cint): cint {. proc posix_fallocate*(a1: cint, a2, a3: TOff): cint {. importc, header: "".} -proc feclearexcept*(a1: cint): cint {.importc, header: "".} -proc fegetexceptflag*(a1: ptr Tfexcept, a2: cint): cint {. - importc, header: "".} -proc feraiseexcept*(a1: cint): cint {.importc, header: "".} -proc fesetexceptflag*(a1: ptr Tfexcept, a2: cint): cint {. - importc, header: "".} -proc fetestexcept*(a1: cint): cint {.importc, header: "".} -proc fegetround*(): cint {.importc, header: "".} -proc fesetround*(a1: cint): cint {.importc, header: "".} -proc fegetenv*(a1: ptr Tfenv): cint {.importc, header: "".} -proc feholdexcept*(a1: ptr Tfenv): cint {.importc, header: "".} -proc fesetenv*(a1: ptr Tfenv): cint {.importc, header: "".} -proc feupdateenv*(a1: ptr Tfenv): cint {.importc, header: "".} - when not defined(haiku) and not defined(OpenBSD): proc fmtmsg*(a1: int, a2: cstring, a3: cint, a4, a5, a6: cstring): cint {.importc, header: "".} diff --git a/lib/pure/math.nim b/lib/pure/math.nim index 8af09114ba..97c7b0e052 100644 --- a/lib/pure/math.nim +++ b/lib/pure/math.nim @@ -40,17 +40,6 @@ const ## after the decimal point ## for Nimrod's ``float`` type. -type - TFloatClass* = enum ## describes the class a floating point value belongs to. - ## This is the type that is returned by `classify`. - fcNormal, ## value is an ordinary nonzero floating point value - fcSubnormal, ## value is a subnormal (a very small) floating point value - fcZero, ## value is zero - fcNegZero, ## value is the negative zero - fcNan, ## value is Not-A-Number (NAN) - fcInf, ## value is positive infinity - fcNegInf ## value is negative infinity - proc classify*(x: float): TFloatClass = ## classifies a floating point value. Returns `x`'s class as specified by ## `TFloatClass`.