Comments (5)
Looks like toPrecision() is like toFixed() while sigFigs is greater than the exponent, and like toExponent() otherwise?
new Decimal(1e11).toPrecision(11)
"1.0000000000e+11"
new Decimal(1e10).toPrecision(11)
"10000000000"
Lemme try that...
from break_infinity.js.
Added, should work the same as decimal.js
from break_infinity.js.
Found a weirdness with toPrecision() on very small numbers.
decimal.js:
new Decimal(1e-6).toPrecision(1)
"0.000001"
new Decimal(1e-7).toPrecision(1)
"1e-7"
new Decimal(1e-300).toPrecision(1)
"1e-300"
new Decimal(1e-300).toPrecision(2)
"1.0e-300"
new Decimal(1e-300).toPrecision(3)
"1.00e-300"
new Decimal(1e-999).toPrecision(1)
"0"
new Decimal(1e-999).toPrecision(2)
"0.0"
new Decimal(1e-999).toPrecision(3)
"0.00"
break_infinity.js:
Everything 'bigger' than 1e-100 is using toFixed, and there is no swap to exponential notation...
new Decimal(1e-100).toPrecision(1)
"0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"
Until...
new Decimal(1e-101).toPrecision(1)
break_infinity.html:312 Uncaught RangeError: toFixed() digits argument must be between 0 and 100
at Number.toFixed (<anonymous>)
at Decimal.toFixed (break_infinity.html:312)
at Decimal.toPrecision (break_infinity.html:319)
at <anonymous>:1:21
Everything 'smaller' than 1e-101 also throws the RangeError.
Not sure about the change in Decimal.js from 1e-300 to 1e-999 suddenly not being exponential anymore, but I'll add the swap to exponential notation, which also fixes the RangeError being thrown.
from break_infinity.js.
My tests pass with this, thanks!
No idea about the small number behavior - swarmsim never gets that small, and swarm-numberformat's not really tested for it either. Unsure if you're done with that part, so I'll let you close this.
from break_infinity.js.
I think it's just a weird thing in decimal.js and the behaviour in break_infinity.js is fine so I'll close
from break_infinity.js.
Related Issues (20)
- break_reality.js when HOT 2
- toFixed returns one more decimal place
- .decimalPlaces() mssing HOT 1
- typescript can not import
- TypeScript import weirdness
- Specify an ignore file for package's published artifacts HOT 1
- theres no break_infinity.js file in the repo HOT 1
- Cv
- 'Typescript definitions' link in readme is dead HOT 1
- Self-division Does not result in 1 HOT 5
- Fix Pow mantissa overflow HOT 1
- I need help HOT 4
- implement isNaN/isFinite HOT 1
- fix unit test failures HOT 7
- Consistency with break eternity.js HOT 1
- cube root is sometimes inaccurate
- Can't convert BigInt to Decimal without throwing an error
- mantissa can be 0.99 HOT 1
- new Decimal('Infinity') returns error from v.2.1.0. HOT 1
- Attempting to view Documentation returns 404
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 break_infinity.js.