all repos — min @ b41dd415a15545159215ebf8bbbb4a2095321185

A small but practical concatenative programming language.

Merge branch 'trig' of https://github.com/PMunch/min into PMunch-trig
h3rald h3rald@h3rald.com
Sat, 28 Oct 2017 09:53:40 +0200
commit

b41dd415a15545159215ebf8bbbb4a2095321185

parent

34de6c3dd6ebd34a80fe90dba143c2cf69706515

3 files changed, 108 insertions(+), 1 deletions(-)

jump to
A lib/min_trig.nim

@@ -0,0 +1,104 @@

+import + tables, + math +import + ../core/parser, + ../core/value, + ../core/interpreter, + ../core/utils + + # Trigonometry + +proc trig_module*(i: In)= + + let def = i.define() + + def.symbol("sin") do (i: In): + let vals = i.expect("num") + let a = vals[0] + if a.isInt: + i.push newVal(sin(a.intVal.float)) + else: + i.push newVal(sin(a.floatVal)) + + def.symbol("cos") do (i: In): + let vals = i.expect("num") + let a = vals[0] + if a.isInt: + i.push newVal(cos(a.intVal.float)) + else: + i.push newVal(cos(a.floatVal)) + + def.symbol("tan") do (i: In): + let vals = i.expect("num") + let a = vals[0] + if a.isInt: + i.push newVal(tan(a.intVal.float)) + else: + i.push newVal(tan(a.floatVal)) + + def.symbol("sinh") do (i: In): + let vals = i.expect("num") + let a = vals[0] + if a.isInt: + i.push newVal(sinh(a.intVal.float)) + else: + i.push newVal(sinh(a.floatVal)) + + def.symbol("cosh") do (i: In): + let vals = i.expect("num") + let a = vals[0] + if a.isInt: + i.push newVal(cosh(a.intVal.float)) + else: + i.push newVal(cosh(a.floatVal)) + + def.symbol("tanh") do (i: In): + let vals = i.expect("num") + let a = vals[0] + if a.isInt: + i.push newVal(tanh(a.intVal.float)) + else: + i.push newVal(tanh(a.floatVal)) + + def.symbol("asin") do (i: In): + let vals = i.expect("num") + let a = vals[0] + if a.isInt: + i.push newVal(arcsin(a.intVal.float)) + else: + i.push newVal(arcsin(a.floatVal)) + + def.symbol("acos") do (i: In): + let vals = i.expect("num") + let a = vals[0] + if a.isInt: + i.push newVal(arccos(a.intVal.float)) + else: + i.push newVal(arccos(a.floatVal)) + + def.symbol("atan") do (i: In): + let vals = i.expect("num") + let a = vals[0] + if a.isInt: + i.push newVal(arctan(a.intVal.float)) + else: + i.push newVal(arctan(a.floatVal)) + + def.symbol("dtr") do (i: In): + let vals = i.expect("num") + let a = vals[0] + if a.isInt: + i.push newVal(degToRad(a.intVal.float)) + else: + i.push newVal(degToRad(a.floatVal)) + + def.symbol("rtg") do (i: In): + let vals = i.expect("num") + let a = vals[0] + if a.isInt: + i.push newVal(radToDeg(a.intVal.float)) + else: + i.push newVal(radToDeg(a.floatVal)) + + def.finalize("trig")
M min.nimmin.nim

@@ -27,7 +27,8 @@ lib/min_logic,

lib/min_time, lib/min_io, lib/min_sys, - lib/min_fs + lib/min_fs, + lib/min_trig when not defined(lite): import lib/min_crypto

@@ -124,6 +125,7 @@ i.str_module

i.sys_module i.time_module i.fs_module + i.trig_module when not defined(lite): i.crypto_module i.eval PRELUDE, "<prelude>"
M prelude.minprelude.min

@@ -9,3 +9,4 @@ 'seq import

'time import 'fs import 'crypto import +'trig import