Skip to content

Commit baae4dd

Browse files
authored
Merge pull request #1815 from ds26gte/log-of-small-nums
js-numbers.js: log() for nonintegral rational arguments = log(numr) - log(denr)
2 parents 025c770 + 31d9295 commit baae4dd

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/js/base/js-numbers.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,11 @@ define("pyret-base/js/js-numbers", function() {
802802
if (typeof(n) === 'number') {
803803
return Roughnum.makeInstance(Math.log(n), errbacks);
804804
}
805+
if (isRational(n) && !isInteger(n)) {
806+
return subtract(log(numerator(n, errbacks), errbacks),
807+
log(denominator(n, errbacks), errbacks),
808+
errbacks);
809+
}
805810
var nFix = n.toFixnum();
806811
if (typeof(nFix) === 'number' && nFix !== Infinity) {
807812
return Roughnum.makeInstance(Math.log(nFix), errbacks);

tests/pyret/tests/test-numbers.arr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ check:
185185
# Racket gives ~84709.80298615794, Wolfram ~84709.80298615795
186186
num-log(1e36789) is-roughly ~84709.80298615796
187187

188+
# Racket gives ~-171658.17010439213, Wolfram 171658.170104392139
189+
num-log(1 / num-expt(9, num-expt(5, 7))) is-roughly ~-171658.17010439216
190+
188191
# Racket, Wolfram match
189192
# commenting because arg calculation takes much time
190193
# num-log(num-expt(10, 1e5)) is-roughly ~230258.50929940457

0 commit comments

Comments
 (0)