# HG changeset patch # User Chris Cannam # Date 1382716548 -3600 # Node ID a9376197529db4b594aa7a2d4526c9ee9daaa2d5 # Parent 604a93b0b24d49af7a45627e993e2e36e5883c3f Add log2, log10 diff -r 604a93b0b24d -r a9376197529d src/may/mathmisc.yeti --- 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, } diff -r 604a93b0b24d -r a9376197529d src/may/mathmisc/test/test_mathmisc.yeti --- 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