Add soft-coded utilites to the "io" and "math" modules. The math
stuff is, for the most part, already available in the geo module; but it's small and this naming matches the evolvoing "standard nasal library".
This commit is contained in:
parent
e7837e32a2
commit
3bcfb0624a
3 changed files with 24 additions and 1 deletions
8
Nasal/io.nas
Normal file
8
Nasal/io.nas
Normal file
|
@ -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;
|
||||
}
|
15
Nasal/math.nas
Normal file
15
Nasal/math.nas
Normal file
|
@ -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; }
|
|
@ -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]
|
||||
|
|
Loading…
Reference in a new issue