diff options
author | rodri <rgl@antares-labs.eu> | 2024-08-31 16:07:55 +0000 |
---|---|---|
committer | rodri <rgl@antares-labs.eu> | 2024-08-31 16:07:55 +0000 |
commit | b94627b33d055c0d644480c9100d19c6318ed9c1 (patch) | |
tree | 90621333ad3865b1c2e675adf00d062f7907b566 /s4/builtin.c | |
parent | 8cca4d1fe83f792d0f3c5dd897611ea2ff441de0 (diff) | |
download | rhoc-front.tar.gz rhoc-front.tar.bz2 rhoc-front.zip |
stage 4 (incomplete).front
Diffstat (limited to 's4/builtin.c')
-rw-r--r-- | s4/builtin.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/s4/builtin.c b/s4/builtin.c new file mode 100644 index 0000000..e9208cf --- /dev/null +++ b/s4/builtin.c @@ -0,0 +1,46 @@ +#include <u.h> +#include <libc.h> +#include "dat.h" +#include "fns.h" +#include "y.tab.h" + +static Const consts[] = { + "π", 3.14159265358979323846, + "e", 2.71828182845904523536, + "γ", 0.57721566490153286060, + "DEG", 57.29577951308232087680, + "Φ", 1.61803398874989484820, +}; + +static Builtin builtins[] = { + "sin", sin, + "cos", cos, + "atan", atan, + "atan2", atan2, + "log", log, + "log10", log10, + "exp", exp, + "sqrt", sqrt, + "int", round, + "abs", fabs, +}; + +double +round(double n) +{ + return floor(n + 0.5); +} + +void +init(void) +{ + Symbol *s; + int i; + + for(i = 0; i < nelem(consts); i++) + install(consts[i].name, CONST, consts[i].val); + for(i = 0; i < nelem(builtins); i++){ + s = install(builtins[i].name, BLTIN, 0); + s->u.fn = builtins[i].fn; + } +} |