changeset 467:a9376197529d

Add log2, log10
author Chris Cannam
date Fri, 25 Oct 2013 16:55:48 +0100
parents 604a93b0b24d
children 38a35e4b41c5
files src/may/mathmisc.yeti src/may/mathmisc/test/test_mathmisc.yeti
diffstat 2 files changed, 26 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/may/mathmisc.yeti	Fri Oct 25 14:37:32 2013 +0100
+++ b/src/may/mathmisc.yeti	Fri Oct 25 16:55:48 2013 +0100
@@ -34,6 +34,14 @@
 ceil x =
     int Math#ceil(x);
 
+log10 x =
+    Math#log10(x);
+
+log2' = Math#log(2);
+
+log2 x =
+    Math#log(x) / log2';
+
 /** 
  * True if x is 2^n for some integer n >= 0.
  */
@@ -64,6 +72,8 @@
     round,
     floor,
     ceil,
+    log10,
+    log2,
     isPowerOfTwo,
     nextPowerOfTwo,
 }
--- a/src/may/mathmisc/test/test_mathmisc.yeti	Fri Oct 25 14:37:32 2013 +0100
+++ b/src/may/mathmisc/test/test_mathmisc.yeti	Fri Oct 25 16:55:48 2013 +0100
@@ -73,6 +73,22 @@
     compare (mm.ceil (-1.5)) (-1.0)
 ),
 
+"log10": \(
+    compare (mm.log10 1) 0 and
+    compare (mm.log10 10) 1 and
+    compare (mm.log10 1e50) 50 and
+    compareUsing do a b: (abs (a-b)) < 1e-12 done
+       (mm.log10 pi) (Math#log(pi) / Math#log(10))
+),
+
+"log2": \(
+    compare (mm.log2 1) 0 and
+    compare (mm.log2 2) 1 and
+    compare (mm.log2 (mm.pow 2 157)) 157 and
+    compareUsing do a b: (abs (a-b)) < 1e-12 done
+       (mm.log2 pi) (Math#log(pi) / Math#log(2))
+),
+
 "isPowerOfTwo": \(
     compare (mm.isPowerOfTwo 0) false and
     compare (mm.isPowerOfTwo 1) true and