From 4c96c9343c9d1738e1eec4405bc3f52bcaf56e30 Mon Sep 17 00:00:00 2001 From: Cat Stevens Date: Thu, 22 Mar 2018 17:13:47 -0400 Subject: [PATCH] basis/math: add logn to math.functions (fix #1981) --- basis/math/functions/functions-docs.factor | 4 ++++ basis/math/functions/functions-tests.factor | 4 ++++ basis/math/functions/functions.factor | 3 +++ 3 files changed, 11 insertions(+) diff --git a/basis/math/functions/functions-docs.factor b/basis/math/functions/functions-docs.factor index 6c1930b463..02c4da0d12 100644 --- a/basis/math/functions/functions-docs.factor +++ b/basis/math/functions/functions-docs.factor @@ -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" } "." } ; diff --git a/basis/math/functions/functions-tests.factor b/basis/math/functions/functions-tests.factor index bc468931e1..da9630d33f 100644 --- a/basis/math/functions/functions-tests.factor +++ b/basis/math/functions/functions-tests.factor @@ -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 diff --git a/basis/math/functions/functions.factor b/basis/math/functions/functions.factor index 010420a66f..aa26be21a9 100644 --- a/basis/math/functions/functions.factor +++ b/basis/math/functions/functions.factor @@ -196,6 +196,9 @@ M: real log >float log ; inline M: complex log >polar [ flog ] dip rect> ; inline +: logn ( x n -- y ) + [ log ] bi@ / ; +