lib/min_trig.nim
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 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") |