Added abs (#81)
h3rald h3rald@h3rald.com
Tue, 12 Jan 2021 22:50:04 +0000
4 files changed,
14 insertions(+),
0 deletions(-)
M
minpkg/lib/min_math.nim
→
minpkg/lib/min_math.nim
@@ -23,6 +23,14 @@
def.symbol("trunc") do (i: In): let vals = i.expect("num") i.push vals[0].getFloat.trunc.newVal + + def.symbol("abs") do (i: In): + let vals = i.expect("num") + let n = vals[0] + if n.kind == minFloat: + i.push n.floatVal.abs.newVal + else: + i.push n.intVal.abs.newVal def.symbol("round") do (i: In): let vals = i.expect("int", "num")
M
next-release.md
→
next-release.md
@@ -1,3 +1,4 @@
* Added **dsinit!** symbol. * Added **sealed?** and **sealed-sigil?** symbols. + **floor** and **ceil** now correctly return an integer again. +* Added **abs** symbol.
M
site/contents/reference-math.md
→
site/contents/reference-math.md
@@ -4,6 +4,9 @@ title: "math Module"
----- {@ _defs_.md || 0 @} +{#op||abs||{{n1}}||{{n2}}|| +Calculates tbe absolute value of {{n1}}. #} + {#op||acos||{{n1}}||{{n2}}|| Calculates the arc cosine of {{n1}} (in radians). #}
M
tests/math.min
→
tests/math.min
@@ -28,6 +28,8 @@
(pi ceil 4 ==) assert (pi trunc 3 ==) assert + + (-2.87 abs 2.87 ==) assert report clear-stack