Giter Site home page Giter Site logo

ios 8 problem about bignumber.js HOT 10 CLOSED

ramarro123 avatar ramarro123 commented on June 11, 2024
ios 8 problem

from bignumber.js.

Comments (10)

MikeMcl avatar MikeMcl commented on June 11, 2024

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.

ramarro123 avatar ramarro123 commented on June 11, 2024

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.

MikeMcl avatar MikeMcl commented on June 11, 2024

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.

ramarro123 avatar ramarro123 commented on June 11, 2024

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.

MikeMcl avatar MikeMcl commented on June 11, 2024

What are the results given for each of the following?

1 % 1e14
2147483647 % 1e14
2147483648 % 1e14
4294967295 % 1e14     
4294967296 % 1e14

from bignumber.js.

ramarro123 avatar ramarro123 commented on June 11, 2024

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.

ramarro123 avatar ramarro123 commented on June 11, 2024

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.

MikeMcl avatar MikeMcl commented on June 11, 2024

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.

ramarro123 avatar ramarro123 commented on June 11, 2024

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.

MikeMcl avatar MikeMcl commented on June 11, 2024

Your fix is correct then.

https://developer.apple.com/bug-reporting/

from bignumber.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.