wtfjs | 🤪 A list of funny and tricky JavaScript examples | Learning library
kandi X-RAY | wtfjs Summary
kandi X-RAY | wtfjs Summary
A list of funny and tricky JavaScript examples
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of wtfjs
wtfjs Key Features
wtfjs Examples and Code Snippets
Community Discussions
Trending Discussions on wtfjs
QUESTION
After I read #magically-increasing-numbers,
so I was wondering about If made calculator with JS how and user put a large number like 9999999999999999
ANSWER
Answered 2021-Sep-06 at 12:33As you already discovered, you ran into an issue with the limited precision of floating point numbers, since your number is outside of the range of "safe integers" which are stored with full precision (it is larger than Number.MAX_SAFE_INTEGER
= 2^53 - 1).
If you only need integers, the native BigInt
type will work just fine (as long as you take care of converting things to/from a BigInt
in the right way):
QUESTION
I was working with some validation that it was supposed to allow integers only, I had something like this:
...ANSWER
Answered 2021-May-04 at 07:11The Javascript standard is actually very clear about the difference between "mathematical values" and Numbers
as represented in the language (https://262.ecma-international.org/11.0/#sec-mathematical-operations)
From the mathematical standpoint, 100.0
is definitely an integer. From the JS standpoint, isInteger(100.0)
is true
, because isInteger
is defined to return true
for Numbers
whose mathematical value is integer.
Your uncertainty comes from the fact in some other languages 100
and 100.0
are indeed quite different things, with different storage mechanisms and the nature of operations performed on them. In Javascript, we actually don't know how a particular number is stored, and have no control over that. The standard says that all Numbers
should behave as if they all were IEEE 754-2019 double values, but what sequence of operations a particular engine actually performs when you compute 1+2
and how they are different from 1.2+3.4
is up to that engine.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install wtfjs
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page