]> gitweb.factorcode.org Git - factor.git/commitdiff
basis/math: add logn to math.functions (fix #1981)
authorCat Stevens <catb0t@protonmail.ch>
Thu, 22 Mar 2018 21:13:47 +0000 (17:13 -0400)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 22 Mar 2018 22:11:45 +0000 (15:11 -0700)
basis/math/functions/functions-docs.factor
basis/math/functions/functions-tests.factor
basis/math/functions/functions.factor

index 6c1930b4637150e2ba31e15777cb9a52aa550c84..02c4da0d126e81ac21e312befdb2317e0a1ba3f5 100644 (file)
@@ -117,6 +117,10 @@ HELP: log
 { $values { "x" number } { "y" number } }
 { $description "Natural logarithm function. Outputs negative infinity if " { $snippet "x" } " is 0." } ;
 
+HELP: logn
+{ $values { "x" number } { "n" number } { "y" number } }
+{ $description "Finds the base " { $snippet "n" } " logarithm of " { $snippet "x" } "." } ;
+
 HELP: log1+
 { $values { "x" number } { "y" number } }
 { $description "Takes the natural logarithm of " { $snippet "1 + x" } ". Outputs negative infinity if " { $snippet "1 + x" } " is zero. This word may be more accurate than " { $snippet "1 + log" } " for very small values of " { $snippet "x" } "." } ;
index bc468931e1319871cfe0bee5c876e60553d33a0a..da9630d33f0ff0878023f1422649c2178f032520 100644 (file)
@@ -69,6 +69,10 @@ IN: math.functions.tests
 { 0.0 } [ 1.0 log ] unit-test
 { 1.0 } [ e log ] unit-test
 
+{ 0.0 } [ 1 e logn ] unit-test
+{ 0.0 } [ 1.0 e logn ] unit-test
+{ 1.0 } [ e e logn ] unit-test
+
 CONSTANT: log-factorial-1000 0x1.71820d04e2eb6p12
 CONSTANT: log10-factorial-1000 0x1.40f3593ed6f8ep11
 
index 010420a66ff05ba5c8b120dfe53807a42ddb5a9d..aa26be21a96b2e3f04ce49aee4f1594b73cdf5e7 100644 (file)
@@ -196,6 +196,9 @@ M: real log >float log ; inline
 
 M: complex log >polar [ flog ] dip rect> ; inline
 
+: logn ( x n -- y )
+  [ log ] bi@ / ;
+
 <PRIVATE
 
 : most-negative-finite-float ( -- x )