-
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
Equality semantics and normalization #11
Comments
What's the use case for differentiation of trailing zeros in |
That library function sounds interesting. Maybe you could explain the semantics and motivation a bit further in #14 ? We have a general invariant in JavaScript, that if two values are Same value/Object.is, then they are totally indistinguishable, and could be thought of as "the same value". So then we wouldn't be able to make that library function work if so. |
In my intuition |
On the other hand, if there will be no Decimal.js and friends do have |
Most use cases won't care or need to think about precision. It's fine if a BigDecimal value can carry precision information, but this shouldn't be considered on any common paths ( |
I think it'd be a pretty big change in how JS works in general if precision were distinguishable according to some library function, but the two values are |
I don't think I agree that most use cases won't care about precision. For example, trailing zeroes are useful in the money case, which I think will be extremely common. @ljharb If you want to argue that BigDecimal should always be normalized, please file an issue arguing that; this issue is about how to handle equality on the basis of a data model which does support trailing zeros. |
My argument imo applies to both; i think it would be very surprising if the same number with different precisions were sometimes distinguishable and sometimes not. Also, this isn’t a proposal for currency or money as i understand it, so the semantic meaning of $ and $2.50 don’t apply to this proposal. In other words, if the proposal is going to consider 2.5 and 2.50 to be different, then I think so should ===, ==, toString, Object.is, etc. |
@ljharb It would be helpful if you could explain where you disagree with @waldemarhorwat's previous arguments, in addition to stating your conclusion. |
@littledan that's a long argument and it seems to require a lot of context, so i'm not sure what specifically i should be disagreeing with. The "Should trailing zeroes be printed when doing toString on decimal values?" question seems to assume that I do agree that trailing zeroes should not be printed, though, which seems to suggest that |
I strongly feel that IEEE decimal trailing zeros should not be distinguishable. You may say that someone wants to distinguish |
Edit: this post seems to have been based on a misunderstanding of Waldemar's proposal; see #11 (comment) for clarification.
Combining @waldemarhorwat's previous proposal with what we have in ES6 and BigInt, I'd imagine that equality semantics may be as follows:
===
andSameValueZero
compare the normalized values==
,<
, etc can compare BigDecimals to other numeric types, according to their mathematical values (following BigInt)SameValue
/Object.is
compares according to the representation of BigDecimal (just one NaN, but differentiating trailing zeroes)Does anyone have concerns with these semantics?
The text was updated successfully, but these errors were encountered: