Move floating point rounding and exceptions handling to math
(it's C99 as well, not just POSIX)
This commit is contained in:
parent
2476ee0cd7
commit
c0422ae8af
2 changed files with 43 additions and 45 deletions
|
|
@ -29,9 +29,6 @@
|
||||||
|
|
||||||
{.deadCodeElim:on.}
|
{.deadCodeElim:on.}
|
||||||
|
|
||||||
when defined(Posix) and not defined(haiku):
|
|
||||||
{.passl: "-lm".}
|
|
||||||
|
|
||||||
from times import TTime
|
from times import TTime
|
||||||
|
|
||||||
const
|
const
|
||||||
|
|
@ -102,22 +99,6 @@ type
|
||||||
l_pid*: TPid ## Process ID of the process holding the lock;
|
l_pid*: TPid ## Process ID of the process holding the lock;
|
||||||
## returned with F_GETLK.
|
## returned with F_GETLK.
|
||||||
|
|
||||||
Tfenv* {.importc: "fenv_t", header: "<fenv.h>", 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: "<fenv.h>", 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: "<ftw.h>", final, pure.} = object
|
TFTW* {.importc: "struct FTW", header: "<ftw.h>", final, pure.} = object
|
||||||
base*: cint
|
base*: cint
|
||||||
level*: cint
|
level*: cint
|
||||||
|
|
@ -837,18 +818,6 @@ var
|
||||||
## The application expects to access the specified data once and
|
## The application expects to access the specified data once and
|
||||||
## then not reuse it thereafter.
|
## then not reuse it thereafter.
|
||||||
|
|
||||||
FE_DIVBYZERO* {.importc, header: "<fenv.h>".}: cint
|
|
||||||
FE_INEXACT* {.importc, header: "<fenv.h>".}: cint
|
|
||||||
FE_INVALID* {.importc, header: "<fenv.h>".}: cint
|
|
||||||
FE_OVERFLOW* {.importc, header: "<fenv.h>".}: cint
|
|
||||||
FE_UNDERFLOW* {.importc, header: "<fenv.h>".}: cint
|
|
||||||
FE_ALL_EXCEPT* {.importc, header: "<fenv.h>".}: cint
|
|
||||||
FE_DOWNWARD* {.importc, header: "<fenv.h>".}: cint
|
|
||||||
FE_TONEAREST* {.importc, header: "<fenv.h>".}: cint
|
|
||||||
FE_TOWARDZERO* {.importc, header: "<fenv.h>".}: cint
|
|
||||||
FE_UPWARD* {.importc, header: "<fenv.h>".}: cint
|
|
||||||
FE_DFL_ENV* {.importc, header: "<fenv.h>".}: cint
|
|
||||||
|
|
||||||
when not defined(haiku) and not defined(OpenBSD):
|
when not defined(haiku) and not defined(OpenBSD):
|
||||||
var
|
var
|
||||||
MM_HARD* {.importc, header: "<fmtmsg.h>".}: cint
|
MM_HARD* {.importc, header: "<fmtmsg.h>".}: cint
|
||||||
|
|
@ -1814,20 +1783,6 @@ proc posix_fadvise*(a1: cint, a2, a3: TOff, a4: cint): cint {.
|
||||||
proc posix_fallocate*(a1: cint, a2, a3: TOff): cint {.
|
proc posix_fallocate*(a1: cint, a2, a3: TOff): cint {.
|
||||||
importc, header: "<fcntl.h>".}
|
importc, header: "<fcntl.h>".}
|
||||||
|
|
||||||
proc feclearexcept*(a1: cint): cint {.importc, header: "<fenv.h>".}
|
|
||||||
proc fegetexceptflag*(a1: ptr Tfexcept, a2: cint): cint {.
|
|
||||||
importc, header: "<fenv.h>".}
|
|
||||||
proc feraiseexcept*(a1: cint): cint {.importc, header: "<fenv.h>".}
|
|
||||||
proc fesetexceptflag*(a1: ptr Tfexcept, a2: cint): cint {.
|
|
||||||
importc, header: "<fenv.h>".}
|
|
||||||
proc fetestexcept*(a1: cint): cint {.importc, header: "<fenv.h>".}
|
|
||||||
proc fegetround*(): cint {.importc, header: "<fenv.h>".}
|
|
||||||
proc fesetround*(a1: cint): cint {.importc, header: "<fenv.h>".}
|
|
||||||
proc fegetenv*(a1: ptr Tfenv): cint {.importc, header: "<fenv.h>".}
|
|
||||||
proc feholdexcept*(a1: ptr Tfenv): cint {.importc, header: "<fenv.h>".}
|
|
||||||
proc fesetenv*(a1: ptr Tfenv): cint {.importc, header: "<fenv.h>".}
|
|
||||||
proc feupdateenv*(a1: ptr Tfenv): cint {.importc, header: "<fenv.h>".}
|
|
||||||
|
|
||||||
when not defined(haiku) and not defined(OpenBSD):
|
when not defined(haiku) and not defined(OpenBSD):
|
||||||
proc fmtmsg*(a1: int, a2: cstring, a3: cint,
|
proc fmtmsg*(a1: int, a2: cstring, a3: cint,
|
||||||
a4, a5, a6: cstring): cint {.importc, header: "<fmtmsg.h>".}
|
a4, a5, a6: cstring): cint {.importc, header: "<fmtmsg.h>".}
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,19 @@ const
|
||||||
## after the decimal point
|
## after the decimal point
|
||||||
## for Nimrod's ``float`` type.
|
## for Nimrod's ``float`` type.
|
||||||
|
|
||||||
|
var
|
||||||
|
FE_DIVBYZERO* {.importc, header: "<fenv.h>".}: cint
|
||||||
|
FE_INEXACT* {.importc, header: "<fenv.h>".}: cint
|
||||||
|
FE_INVALID* {.importc, header: "<fenv.h>".}: cint
|
||||||
|
FE_OVERFLOW* {.importc, header: "<fenv.h>".}: cint
|
||||||
|
FE_UNDERFLOW* {.importc, header: "<fenv.h>".}: cint
|
||||||
|
FE_ALL_EXCEPT* {.importc, header: "<fenv.h>".}: cint
|
||||||
|
FE_DOWNWARD* {.importc, header: "<fenv.h>".}: cint
|
||||||
|
FE_TONEAREST* {.importc, header: "<fenv.h>".}: cint
|
||||||
|
FE_TOWARDZERO* {.importc, header: "<fenv.h>".}: cint
|
||||||
|
FE_UPWARD* {.importc, header: "<fenv.h>".}: cint
|
||||||
|
FE_DFL_ENV* {.importc, header: "<fenv.h>".}: cint
|
||||||
|
|
||||||
type
|
type
|
||||||
TFloatClass* = enum ## describes the class a floating point value belongs to.
|
TFloatClass* = enum ## describes the class a floating point value belongs to.
|
||||||
## This is the type that is returned by `classify`.
|
## This is the type that is returned by `classify`.
|
||||||
|
|
@ -51,6 +64,22 @@ type
|
||||||
fcInf, ## value is positive infinity
|
fcInf, ## value is positive infinity
|
||||||
fcNegInf ## value is negative infinity
|
fcNegInf ## value is negative infinity
|
||||||
|
|
||||||
|
Tfenv* {.importc: "fenv_t", header: "<fenv.h>", 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: "<fenv.h>", 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 classify*(x: float): TFloatClass =
|
proc classify*(x: float): TFloatClass =
|
||||||
## classifies a floating point value. Returns `x`'s class as specified by
|
## classifies a floating point value. Returns `x`'s class as specified by
|
||||||
## `TFloatClass`.
|
## `TFloatClass`.
|
||||||
|
|
@ -321,6 +350,20 @@ proc standardDeviation*(s: TRunningStat): float =
|
||||||
## computes the current standard deviation of `s`
|
## computes the current standard deviation of `s`
|
||||||
result = sqrt(variance(s))
|
result = sqrt(variance(s))
|
||||||
|
|
||||||
|
proc feclearexcept*(a1: cint): cint {.importc, header: "<fenv.h>".}
|
||||||
|
proc fegetexceptflag*(a1: ptr Tfexcept, a2: cint): cint {.
|
||||||
|
importc, header: "<fenv.h>".}
|
||||||
|
proc feraiseexcept*(a1: cint): cint {.importc, header: "<fenv.h>".}
|
||||||
|
proc fesetexceptflag*(a1: ptr Tfexcept, a2: cint): cint {.
|
||||||
|
importc, header: "<fenv.h>".}
|
||||||
|
proc fetestexcept*(a1: cint): cint {.importc, header: "<fenv.h>".}
|
||||||
|
proc fegetround*(): cint {.importc, header: "<fenv.h>".}
|
||||||
|
proc fesetround*(a1: cint): cint {.importc, header: "<fenv.h>".}
|
||||||
|
proc fegetenv*(a1: ptr Tfenv): cint {.importc, header: "<fenv.h>".}
|
||||||
|
proc feholdexcept*(a1: ptr Tfenv): cint {.importc, header: "<fenv.h>".}
|
||||||
|
proc fesetenv*(a1: ptr Tfenv): cint {.importc, header: "<fenv.h>".}
|
||||||
|
proc feupdateenv*(a1: ptr Tfenv): cint {.importc, header: "<fenv.h>".}
|
||||||
|
|
||||||
{.pop.}
|
{.pop.}
|
||||||
{.pop.}
|
{.pop.}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue