all repos — min @ 299c77345d43563bc2f86095ac2d0f23e0e80ffe

A small but practical concatenative programming language.

Added abs (#81)
h3rald h3rald@h3rald.com
Tue, 12 Jan 2021 22:50:04 +0000
commit

299c77345d43563bc2f86095ac2d0f23e0e80ffe

parent

060ffb02f582d26207e28237b0fa63311e34f419

4 files changed, 14 insertions(+), 0 deletions(-)

jump to
M minpkg/lib/min_math.nimminpkg/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.mdnext-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.mdsite/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.mintests/math.min

@@ -28,6 +28,8 @@

(pi ceil 4 ==) assert (pi trunc 3 ==) assert + + (-2.87 abs 2.87 ==) assert report clear-stack