From ffcc630601b6ba5b3c5c6bca81ef9def5b7f04a5 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Fri, 11 Sep 2009 20:28:15 -0500 Subject: [PATCH 1/3] log1+ word (maps to C99 log1p function) --- basis/math/functions/functions-docs.factor | 5 +++++ basis/math/functions/functions.factor | 8 +++++++- basis/math/libm/libm.factor | 3 +++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/basis/math/functions/functions-docs.factor b/basis/math/functions/functions-docs.factor index 114b92ecde..134cbd398c 100644 --- a/basis/math/functions/functions-docs.factor +++ b/basis/math/functions/functions-docs.factor @@ -51,6 +51,7 @@ ARTICLE: "power-functions" "Powers and logarithms" { $subsection exp } { $subsection cis } { $subsection log } +{ $subsection log1+ } { $subsection log10 } "Raising a number to a power:" { $subsection ^ } @@ -125,6 +126,10 @@ HELP: log { $values { "x" number } { "y" number } } { $description "Natural logarithm function. Outputs negative infinity if " { $snippet "x" } " is 0." } ; +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" } "." } ; + HELP: log10 { $values { "x" number } { "y" number } } { $description "Logarithm function base 10. Outputs negative infinity if " { $snippet "x" } " is 0." } ; diff --git a/basis/math/functions/functions.factor b/basis/math/functions/functions.factor index 92f16764c0..0cf9467795 100644 --- a/basis/math/functions/functions.factor +++ b/basis/math/functions/functions.factor @@ -163,7 +163,13 @@ M: float log dup 0.0 >= [ flog ] [ 0.0 rect> log ] if ; inline M: real log >float log ; inline -M: complex log >polar swap flog swap rect> ; inline +M: complex log >polar [ flog ] dip rect> ; inline + +GENERIC: log1+ ( x -- y ) + +M: object log1+ 1 + log ; inline + +M: float log1+ dup -1.0 >= [ flog1+ ] [ 1.0 + 0.0 rect> log ] if ; inline : 10^ ( x -- y ) 10 swap ^ ; inline diff --git a/basis/math/libm/libm.factor b/basis/math/libm/libm.factor index e2bd2ef6eb..0ebc96a05c 100644 --- a/basis/math/libm/libm.factor +++ b/basis/math/libm/libm.factor @@ -46,6 +46,9 @@ IN: math.libm "double" "libm" "sqrt" { "double" } alien-invoke ; ! Windows doesn't have these... +: flog1p ( x -- y ) + "double" "libm" "log1p" { "double" } alien-invoke ; + : facosh ( x -- y ) "double" "libm" "acosh" { "double" } alien-invoke ; From 67893e5af989457ab4a11e3a30e3e4243102894d Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Fri, 11 Sep 2009 20:29:02 -0500 Subject: [PATCH 2/3] json.reader doesn't need to USE: math.parser.private anymore since I made float>string public --- basis/json/reader/reader.factor | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/basis/json/reader/reader.factor b/basis/json/reader/reader.factor index 9886e316d7..bdfeaa3e51 100644 --- a/basis/json/reader/reader.factor +++ b/basis/json/reader/reader.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2008 Peter Burns, 2009 Philipp Winkler ! See http://factorcode.org/license.txt for BSD license. USING: arrays assocs combinators io io.streams.string json -kernel math math.parser math.parser.private prettyprint +kernel math math.parser prettyprint sequences strings vectors ; IN: json.reader @@ -100,4 +100,4 @@ DEFER: j-string PRIVATE> : json> ( string -- object ) - (json-parser>) ; \ No newline at end of file + (json-parser>) ; From 1be4c3a6a76b1a4cd914ec9efb5db7a1f9b33221 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Fri, 11 Sep 2009 20:31:06 -0500 Subject: [PATCH 3/3] typo --- basis/math/libm/libm.factor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basis/math/libm/libm.factor b/basis/math/libm/libm.factor index 0ebc96a05c..1ac0ec0ae7 100644 --- a/basis/math/libm/libm.factor +++ b/basis/math/libm/libm.factor @@ -46,7 +46,7 @@ IN: math.libm "double" "libm" "sqrt" { "double" } alien-invoke ; ! Windows doesn't have these... -: flog1p ( x -- y ) +: flog1+ ( x -- y ) "double" "libm" "log1p" { "double" } alien-invoke ; : facosh ( x -- y )