Skip to content
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

[SR-5678] Decimal initializer result is unexpected #4083

Closed
swift-ci opened this issue Aug 12, 2017 · 3 comments
Closed

[SR-5678] Decimal initializer result is unexpected #4083

swift-ci opened this issue Aug 12, 2017 · 3 comments

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-5678
Radar None
Original Reporter BenLeggiero (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee BenLeggiero (JIRA)
Priority Medium

md5: fa3bc5022050cf27fced9d845fe3a0f4

duplicates:

  • SR-3317 Literal protocol for decimal literals should support precise decimal accuracy

Issue Description:

Discovery and elaboration here: https://stackoverflow.com/a/45584335/3939277

Quick example:

let x = Decimal(1e256)
print(x) // 1.0000000000000008192
@swift-ci
Copy link
Contributor Author

Comment by Ky (JIRA)

I think that should be a failable initializer, returning nil for any input it cannot precisely represent, or at least that would overflow

@belkadan
Copy link

Decimal is arbitrary-precision; the thing that "overflows" is the literal (which is interpreted as a Double). But I wouldn't expect it to truncate either. @jckarter, do you understand what's going on?

@jckarter
Copy link
Member

You described it accurately. Swift's literal initialization model for decimal literals is to pass them as floats. Ideally Decimal would not have provided this initializer until we had proper support for accurate decimal literals, but that's ultimately SR-3317.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants