-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
BigDecimal literal syntax #7
Comments
Should |
Offline, @bkardell proposed |
I like |
After some googling (correct me if I got something wrong):
I don't see strong consensus here - most of the popular languages are missing this feature, so there will be no much harm to choose some different suffix than |
I propose we just use Even if their implementations are different their semantics are very much the same. It's also not a big deal to support both decimals and integers having similar syntax in terms of parser writing. I suppose I can change a few lines in the Terser parser and this goes right in. |
@fabiosantoscode n is already used for BigInt. It would be exceedingly confusing if 5.0n produced a BigInt and 5.01n produced a BigDecimal. |
@ljharb isn't |
I was imagining that it'd be possible to have BigDecimal literals that didn't have a literal decimal point in them, e.g., |
@ljharb What about extending BigInt to BigDecimal? I mean, let BigDecimal be supertype of BigInt, then we could easily solve the problem about ambiguity & confusing syntax. I was wondering why we should separate BigInt and BigDecimal. If we do so, we can’t simply write function that parametrically polymorphic to BigInt & BigDecimal but we would use function like ‘matchBigNumbers(BigN1, BigN2)’, which makes code long. |
@ENvironmentSet I think that would lead to certain mismatches. For one, division in BigInt is integer division (which many developers told us was an important use case), but in BigDecimal, we may want to give a more precise answer, or trigger an error (discussed further in #13). |
How about an |
@wheresrhys It would make |
I can imaging cases where |
I don't like how |
@chicoxyzzy |
Due to #36 , I think we should avoid About a trailing |
Maybe the trailing decimal should warrant a separate issue; it feels like a mistake nobody wants that would be a shame to replicate. |
I think |
It seems that this issue has been resolved. Shall we close it? |
Based on feedback received at plenary about this issue, it looks like adding new literal syntax for decimals is, as of today, too heavy of a lift for some of the engine implementors. (That's not to say that it's not a bad idea and that we couldn't return to the issue sometime down the road.) |
I don't think the pushback was about new syntax as much as it was about "a new primitive" and |
IIRC I thought that the argument for "no new syntax" did indeed involve Assumptions:
Given those assumptions, we would be led to the awkward situation where In other words, adding new literals without overloading would lead to confusion. That was my takeaway, anyway. Maybe I'm getting the argument wrong. |
Following the rough consensus of several programming languages as well as TC39 tradition, this proposal uses the syntax
123.456m
for BigDecimal literals. (Maybe m stands for Money?) Is this a reasonable syntax, or are there any issues?The text was updated successfully, but these errors were encountered: