diff --git a/Nasal/io.nas b/Nasal/io.nas new file mode 100644 index 000000000..fdd65ead3 --- /dev/null +++ b/Nasal/io.nas @@ -0,0 +1,8 @@ +# Reads and returns a complete file as a string +var readfile = func(file) { + if((var st = stat(file)) == nil) die("Cannot stat file: " ~ file); + var sz = st[7]; + var buf = bits.buf(sz); + read(open(file), buf, sz); + return buf; +} diff --git a/Nasal/math.nas b/Nasal/math.nas new file mode 100644 index 000000000..554329aaa --- /dev/null +++ b/Nasal/math.nas @@ -0,0 +1,15 @@ +var abs = func(n) { n < 0 ? -n : n } + +var pow = func(x, y) { exp(y * ln(x)) } + +var mod = func(n, m) { + var x = n - m * int(n/m); # int() truncates to zero, not -Inf + return x < 0 ? x + abs(m) : x; # ...so must handle negative n's +} + +var asin = func(y) { atan2(y, sqrt(1-y*y)) } + +var acos = func(x) { atan2(sqrt(1-x*x), x) } + +var _iln10 = 1/ln(10); +var log10 = func(x) { ln(x) * _iln10; } diff --git a/Nasal/props.nas b/Nasal/props.nas index fb94d8b81..7ce608dde 100644 --- a/Nasal/props.nas +++ b/Nasal/props.nas @@ -164,7 +164,7 @@ var wrapNode = func { { parents : [Node], _g : arg[0] } } # Does anything ever call globals.set_props() from C++? May need to # turn this into a function if so. # -props.globals = wrapNode(_globals()); +var globals = wrapNode(_globals()); ## # Sets all indexed property children to a single value. arg[0]