parent
069a53ad4b
commit
a3e5242d31
2 changed files with 14 additions and 1 deletions
|
|
@ -65,6 +65,7 @@
|
||||||
- Added cotangent, secant and cosecant procs ``math.cot``, ``math.sec`` and ``math.csc``; and their hyperbolic, inverse and inverse hyperbolic functions, ``math.coth``, ``math.sech``, ``math.csch``, ``math.arccot``, ``math.arcsec``, ``math.arccsc``, ``math.arccoth``, ``math.arcsech`` and ``math.arccsch`` procs.
|
- Added cotangent, secant and cosecant procs ``math.cot``, ``math.sec`` and ``math.csc``; and their hyperbolic, inverse and inverse hyperbolic functions, ``math.coth``, ``math.sech``, ``math.csch``, ``math.arccot``, ``math.arcsec``, ``math.arccsc``, ``math.arccoth``, ``math.arcsech`` and ``math.arccsch`` procs.
|
||||||
- Added the procs ``math.floorMod`` and ``math.floorDiv`` for floor based integer division.
|
- Added the procs ``math.floorMod`` and ``math.floorDiv`` for floor based integer division.
|
||||||
- Added the procs ``rationals.`div```, ``rationals.`mod```, ``rationals.floorDiv`` and ``rationals.floorMod`` for rationals.
|
- Added the procs ``rationals.`div```, ``rationals.`mod```, ``rationals.floorDiv`` and ``rationals.floorMod`` for rationals.
|
||||||
|
- Added the proc ``math.prod`` for product of elements in openArray.
|
||||||
|
|
||||||
### Library changes
|
### Library changes
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -129,6 +129,12 @@ proc sum*[T](x: openArray[T]): T {.noSideEffect.} =
|
||||||
## If `x` is empty, 0 is returned.
|
## If `x` is empty, 0 is returned.
|
||||||
for i in items(x): result = result + i
|
for i in items(x): result = result + i
|
||||||
|
|
||||||
|
proc prod*[T](x: openArray[T]): T {.noSideEffect.} =
|
||||||
|
## Computes the product of the elements in ``x``.
|
||||||
|
## If ``x`` is empty, 1 is returned.
|
||||||
|
result = 1.T
|
||||||
|
for i in items(x): result = result * i
|
||||||
|
|
||||||
{.push noSideEffect.}
|
{.push noSideEffect.}
|
||||||
when not defined(JS): # C
|
when not defined(JS): # C
|
||||||
proc sqrt*(x: float32): float32 {.importc: "sqrtf", header: "<math.h>".}
|
proc sqrt*(x: float32): float32 {.importc: "sqrtf", header: "<math.h>".}
|
||||||
|
|
@ -560,6 +566,12 @@ when isMainModule:
|
||||||
# Function for approximate comparison of floats
|
# Function for approximate comparison of floats
|
||||||
proc `==~`(x, y: float): bool = (abs(x-y) < 1e-9)
|
proc `==~`(x, y: float): bool = (abs(x-y) < 1e-9)
|
||||||
|
|
||||||
|
block: # prod
|
||||||
|
doAssert prod([1, 2, 3, 4]) == 24
|
||||||
|
doAssert prod([1.5, 3.4]) == 5.1
|
||||||
|
let x: seq[float] = @[]
|
||||||
|
doAssert prod(x) == 1.0
|
||||||
|
|
||||||
block: # round() tests
|
block: # round() tests
|
||||||
# Round to 0 decimal places
|
# Round to 0 decimal places
|
||||||
doAssert round(54.652) ==~ 55.0
|
doAssert round(54.652) ==~ 55.0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue