From 60da2d4da8dd6a7e9cf77589b50f456e83bb80c3 Mon Sep 17 00:00:00 2001 From: James Turner Date: Thu, 3 Oct 2013 17:42:20 +0100 Subject: [PATCH] Remove items implement natively in Nasal. mathlib.c now defines more of these. Remaining items (abs, sgn, min, max) are likely faster using Nasal than switching to C and back again. Also add a comment about mod(), clarifying that a native fmod() exists. --- Nasal/math.nas | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Nasal/math.nas b/Nasal/math.nas index d9a94f278..94f79f343 100644 --- a/Nasal/math.nas +++ b/Nasal/math.nas @@ -27,18 +27,13 @@ var avg = func { return x; } -var pow = func(x, y) { exp(y * ln(x)) } - +# note - mathlib defines an fmod function (added after this was written) +# It uses C-library fmod(), which has different rounding behaviour to +# this code (eg, fmod(-5, 4) gives -1, whereas this code gives 3) 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 tan = func(x) { sin(x) / (cos(x) or die("tangens infinity")) } - var _iln10 = 1/ln(10); var log10 = func(x) { ln(x) * _iln10 }