-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace built-in types? #57
Comments
Computers don’t work in base10 arithmetic and programmers don’t care about non technicians. If you will do any computation in base10, libraries like three.js will be slow. |
That's fine.
That's not true. In fact, programmers care much about non technicians and often about other programmers. Did you use any software where you was forced to enter data in base2? Beside some cases, as a programmer, you use But this isn't topic to discuss in this proposal. Bitwise operations and conversions are fine. But naïve reliance on floating point arithmetic is bad, very bad. BigInt makes this situation even worse, because it introduces/reserves new syntax and takes only integers into account. It's hard to find use cases in real world applications. But there endless cases for decimals. This proposal is about fixing the |
This is a breaking change. Web usually doesn’t break things. Also https://0.30000000000000004.com/ |
Another "problem" is that |
Be aware: it's not a concept, but just a raw idea. Because IEEE 754 isn't precise for relevant extent anyway, may be it's better to replace the built-in type(s) under the hood with sensitive defaults. The current way to deal with integers, floats, BigInt doesn't feel right from mathematical (try to explain 0.1 + 0.2 to non-technician) or syntax (
n
?d
? Or p?) views. I'm not sure why developers should even care about it, except of some edge cases. It should "just work".For example,
n
or classes likeBigDecimal
/BigInt
are needed. Just use+
,-
and other already known operations..toString()
returns only significant numbers (strip all tail zeros). For example:console.log(0.1 + 0.2)
prints0.3
andconsole.log(0.1010)
prints0.101
.Now tricky part.
Custom printing:
console.log(0.1234000.toString({rounding: Number.Rounding.Scientific}))
.Rounding:
0.1234.round(3, Number.Rounding.HalfUp)
.Converting:
0.1234.toBase(2)
,0.1234.toHex()
.Division with custom precision. This is a hard one. May be like
1.div(3, 17)
or1 /17 3
. The last one can leads to errors. But we have already something like with regexp:/^\d+$/.test('123')
. And in most cases there is no need to change the default anyway.Above examples are not consistent and are, well, just examples. I like to pass Objects as args, because it's more readable, but often people like indexed arguments.
I'm also aware that it would be a very large breaking change in sense of semantic. But in my opinion it's very important that math operations work in a (more) predictable way.
What do you think about it?
The text was updated successfully, but these errors were encountered: