Skip to content

Commit 18a7656

Browse files
committed
add better fix for IEEE error
1 parent 54062cf commit 18a7656

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/core.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ var slice = Array.prototype.slice,
2626
// test if object
2727
isObject = function( arg ) {
2828
return toString.call( arg ) === "[object Object]";
29+
},
30+
31+
// calculate correction for IEEE
32+
calcRdx = function( n, m ) {
33+
var val = n > m ? n : m;
34+
return Math.pow( 10, 15 - ~~( Math.log((( val > 0 ) ? val : -val )) * Math.LOG10E ));
2935
};
3036

3137
// implement bind if browser doesn't natively support it
@@ -290,7 +296,7 @@ jStat.extend({
290296
// generate sequence
291297
seq : function( min, max, length, func ) {
292298
var arr = [],
293-
hival = 1e15, // simple fix for IEEE floating point errors
299+
hival = calcRdx( min, max ),
294300
step = ( max * hival - min * hival ) / (( length - 1 ) * hival ),
295301
current = min,
296302
cnt = 0;

0 commit comments

Comments
 (0)