Nim's Python-like math, but raises no catchable exception, using errno to report math error. a.k.a. non will be raised (but not for Defects)
which allows fast code.
For Python-like error handler (exception-based), see Lib/math
Also this is not just a module that wraps Nim's std/math,
but also providing some extensions that Nim's std/math lacks, for example:
- JavaScript Backend and Compile-time (Nim VM) support for ldexp, frexp
- JavaScript Backend support for erf, erfc, gamma, lgamma
- fsum, prod, etc.
And fix some non-C99 behavior on some systems, e.g. log(-ve) -> -Inf on Solaris
NOTE: Currently int is not acceptable when it comes to float about functions
Procs
func comb(n, k: int): int {....raises: [], tags: [], forbids: [].}
-
Hint: Python's math.comb does not accept negative value for n, k but Nim's std/math.binom allows, so this function allows too. For consistent behavior with Python, see Lib/math.combSource Edit
func isqrtPositive(n: Positive): int {.inline, ...raises: [], tags: [], forbids: [].}
-
EXT: isqrt for Positive only, as we all know, in Python:
- isqrt(0) == 0
- isqrt(-int)
func math_is_error(x: SomeFloat; exc: var ref Exception): bool
-
inner usage (used by Lib/math).
Call this when errno != 0, and where x is the result libm returned. This will usually set up an exception and return true, but may return false without setting up an exception.
Source Edit
Templates
template py_math_isclose_impl(abs)
-
inner use. Implementation of isclose.
mixin a, b, isinf, rel_tol, abs_tol
Source Edit