Comments (10)
How strange. Unfortunately, I can not try it myself at the moment.
What does 1e14 % 1e14
produce in the console?
Please post the result of adding console.dir(a)
to your snippet so I can see the c
, e
and s
properties of a
.
from bignumber.js.
modified the code as follow
<script> var a = new BigNumber(0.5); var b = new BigNumber(0.5); a = a.plus(b); console.log("printing +a"); console.log(+a); console.log("printing console.dir(a)"); console.dir(a); console.log("printing 1e1%1e1"); console.log(1e1 % 1e1); console.log("printing 1e5%1e5"); console.log(1e5 % 1e5); console.log("printing 1e7%1e7"); console.log(1e7 % 1e7); console.log("printing 1e8%1e8"); console.log(1e8 % 1e8); console.log("printing 1e9%1e9"); console.log(1e9 % 1e9); console.log("printing 1e10%1e10"); console.log(1e10 % 1e10); console.log("printing 1e11%1e11"); console.log(1e11 % 1e11); console.log("printing 1e12%1e12"); console.log(1e12 % 1e12); console.log("printing 1e13%1e13"); console.log(1e13 % 1e13); console.log("printing 1e14%1e14"); console.log(1e14 % 1e14); console.log("printing 1e15%1e15"); console.log(1e15 % 1e15); </script>output: (i have try to 'beautify' the report)
---------------------------------------------------------------- KO (a is NaN)
[Log] printing +a (test.html, line 10)
[Log] NaN (test.html, line 11)
---------------------------------------------------------------- KO (please note c[1])
[Log] printing console.dir(a) (test.html, line 13)
[Log] BigNumber (test.html, line 14)
c: Array[2]
0: 1
1: 2.5333397e-315
length: 2
proto: Array[0]
e: 0
s: 1
proto: BigNumber
---------------------------------------------------------------- OK
[Log] printing 1e1%1e1 (test.html, line 17)
[Log] 0 (test.html, line 18)
---------------------------------------------------------------- OK
[Log] printing 1e5%1e5 (test.html, line 20)
[Log] 0 (test.html, line 21)
---------------------------------------------------------------- OK
[Log] printing 1e7%1e7 (test.html, line 23)
[Log] 0 (test.html, line 24)
---------------------------------------------------------------- OK
[Log] printing 1e8%1e8 (test.html, line 26)
[Log] 0 (test.html, line 27)
---------------------------------------------------------------- OK
[Log] printing 1e9%1e9 (test.html, line 29)
[Log] 0 (test.html, line 30)
---------------------------------------------------------------- KO!!!
[Log] printing 1e10%1e10 (test.html, line 32)
[Log] 2.65249474e-315 (test.html, line 33)
---------------------------------------------------------------- KO!!!
[Log] printing 1e11%1e11 (test.html, line 35)
[Log] 1.9230586856e-314 (test.html, line 36)
---------------------------------------------------------------- KO!!!
[Log] printing 1e12%1e12 (test.html, line 38)
[Log] 1.3428254615e-314 (test.html, line 39)
---------------------------------------------------------------- KO!!!
[Log] printing 1e13%1e13 (test.html, line 41)
[Log] 1.900263809e-314 (test.html, line 42)
---------------------------------------------------------------- KO!!!
[Log] printing 1e14%1e14 (test.html, line 44)
[Log] 2.5333397e-315 (test.html, line 45)
---------------------------------------------------------------- KO!!!
[Log] printing 1e15%1e15 (test.html, line 48)
[Log] 3.166674627e-315 (test.html, line 49)
from bignumber.js.
Thanks.
It looks like the %
operator has problems with operands over 32 bits, which seems to be a surprisingly rudimentary failing of the JavaScript implementation.
I am reluctant to apply a fix to work round it here at this stage, but further details/confirmation of this issue would be welcome.
from bignumber.js.
if you can share the snippet code with the fix, i will apply it locally eventually.
this issue unfortunatly prevent me to use this lib, as i work in mobile env.
I don't think that my fix is correct, probably it will be not too much fork for you to put out a fix for that, even locally or in a special version
from bignumber.js.
What are the results given for each of the following?
1 % 1e14
2147483647 % 1e14
2147483648 % 1e14
4294967295 % 1e14
4294967296 % 1e14
from bignumber.js.
here we go
[Log] printing 1 % 1e14 (test.html, line 17)
[Log] 1 (test.html, line 18)
[Log] printing 2147483647 % 1e14 (test.html, line 20)
[Log] 2147483647 (test.html, line 21)
[Log] printing 2147483648 % 1e14 (test.html, line 23)
[Log] 2147483648 (test.html, line 24)
[Log] printing 4294967295 % 1e14 (test.html, line 26)
[Log] 4294967295 (test.html, line 27)
[Log] printing 4294967296 % 1e14 (test.html, line 29)
[Log] 4294967296 (test.html, line 30)
from bignumber.js.
code modified as follow
console.log("printing 1 % 1e14");
console.log(1 % 1e14);
console.log("printing 2147483647 % 1e14");
console.log(2147483647 % 1e14);
console.log("printing 2147483648 % 1e14");
console.log(2147483648 % 1e14);
console.log("printing 4294967295 % 1e14");
console.log(4294967295 % 1e14);
console.log("printing 4294967296 % 1e14");
console.log(4294967296 % 1e14);
from bignumber.js.
Oh, so it just seems to fail when the first operand equals the second operand.
1e14 % 1e14 // 2.5333397e-315 fail
(1e14+1) % 1e14 // 1 okay
(1e14-1) % 1e14 // 99999999999999 okay
Is that correct?
from bignumber.js.
confirmed!!
[Log] printing 1e14 % 1e14 (test.html, line 17)
[Log] 2.5333397e-315 (test.html, line 18)
[Log] printing (1e14+1) % 1e14 (test.html, line 20)
[Log] 1 (test.html, line 21)
[Log] printing (1e14-1) % 1e14 (test.html, line 23)
[Log] 99999999999999 (test.html, line 24)
from bignumber.js.
Your fix is correct then.
https://developer.apple.com/bug-reporting/
from bignumber.js.
Related Issues (20)
- Using version 9.1.1, run new BigNumber(0).exponentiatedBy('-12345678901234567890123456789012345678901234567890').valueOf() Is return to infinity normal? HOT 1
- Issue toNumber() function round up when number is too big (v9.1.1) HOT 2
- Division on exponential values leads to infinite loop HOT 3
- 负数加减乘除不好用 HOT 1
- [Feature Request]: Can we support `toBigInt`?
- Type error HOT 2
- Big Number (toFixed,dp,decimalPlaces,toFormat) - Chrome Update Issue 115.0.5790.102 HOT 24
- Minus sign in formatted strings HOT 2
- wrong calculation result on multipliedBy/times methods HOT 1
- toNumber does not respect ROUNDING_MODE HOT 11
- Calculation error HOT 1
- Is there any other way to handle new BigNumber(999999999999999999999) without using strings? HOT 2
- Difference between multipliedBy and dividedBy behaviors HOT 2
- Different result between toFixed and toNumber HOT 1
- Can't convert to Base64 HOT 1
- Tree shake commonjs version from mjs version HOT 1
- toFixed error
- [Bug] Return Type of Methods HOT 2
- Logarithms (I know there is another issue about this)
- toString() default base is not 10? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bignumber.js.