Giter Site home page Giter Site logo

Comments (8)

Patashu avatar Patashu commented on June 20, 2024

Woah, I haven't seen this '2n' thing before. Is it a new Javascript feature?

from break_eternity.js.

James103 avatar James103 commented on June 20, 2024

Woah, I haven't seen this '2n' thing before. Is it a new Javascript feature?

The syntax used describes something called BigInts, which are supported on the most recent version of all major browsers. BigInts effectively allow storing numbers much larger than 21024 with full precision (down to the nearest whole number), with their size effectively only being limited only by available memory.

For more information on BigInts, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt

from break_eternity.js.

Patashu avatar Patashu commented on June 20, 2024

Cutting edge! I'll take a look at supporting BigInts if I find the time and mood.

from break_eternity.js.

James103 avatar James103 commented on June 20, 2024

You can convert a BigInt to a String with String(bigint) or bigint.toString() and you can construct a Decimal from a string of digits with new Decimal(string). However, Decimal.fromString fails to properly parse strings of digits that are more than 309 digits long, as such strings become Infinity when coerced to Number.

Number("1".repeat(309))
1.1111111111111112e+308

Number("1".repeat(310))
Infinity

from break_eternity.js.

Patashu avatar Patashu commented on June 20, 2024

I guess it'd be sufficient to detect the string is longer than 300 digits, grab the first 18 of them, and turn it into mantissa and exponent.

from break_eternity.js.

1231234md5 avatar 1231234md5 commented on June 20, 2024

#145 will fix it

from break_eternity.js.

jakub791 avatar jakub791 commented on June 20, 2024

I guess it'd be sufficient to detect the string is longer than 300 digits, grab the first 18 of them, and turn it into mantissa and exponent.

Couldn't you toString() the bigint, remove the n from the string then let toString() method do it's job as usual?

from break_eternity.js.

1231234md5 avatar 1231234md5 commented on June 20, 2024

I guess it'd be sufficient to detect the string is longer than 300 digits, grab the first 18 of them, and turn it into mantissa and exponent.

Couldn't you toString() the bigint, remove the n from the string then let toString() method do it's job as usual?

but that's what #145 does.

from break_eternity.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.