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-3317] Literal protocol for decimal literals should support precise decimal accuracy #45905

jckarter opened this issue Dec 2, 2016 · 3 comments


Copy link

jckarter commented Dec 2, 2016

Previous ID SR-3317
Radar rdar://problem/31414910
Original Reporter @jckarter
Type Bug
Status Resolved
Resolution Duplicate
Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug, AffectsABI, StarterProposal
Assignee None
Priority Medium

md5: 9de0502502b261886bad92d969cec324


  • SR-920 Re-design builtin compiler protocols for literal convertible types

is duplicated by:

  • SR-5678 Decimal initializer result is unexpected

relates to:

  • SR-3970 Rework ExpressibleBy(Integer|Float)Literal protocols

Issue Description:

A decimal literal such as 1.23 currently constructs a value via the ExpressibleByFloatLiteral protocol, which eagerly parses the literal into a binary floating-point value, losing accuracy. ExpressibleByFloatLiteral is unsuitable for supporting decimal float or fixed-point types. We should introduce an ExpressibleByDecimalLiteral protocol that can receive the significand, exponent, and sign components of a decimal literal as precise integers, so that a conforming type can produce a precise result. It could look something like this:

protocol ExpressibleByDecimalLiteral {
  associatedtype Exponent: ExpressibleByIntegerLiteral
  associatedtype Significand: ExpressibleByIntegerLiteral
  init(negative: Bool, significand: Significand, exponent: Exponent)

ExpressibleByFloatLiteral could be made into a refinement of ExpressibleByDecimalLiteral as well.

Copy link

bob-wilson commented Apr 3, 2017

@swift-ci create

Copy link

swift-ci commented Nov 21, 2017

Comment by Ky (JIRA)

This is marked resolved; in what version of Swift was it introduced? I'm assuming 4.1...?

Copy link

bob-wilson commented Nov 21, 2017

It is resolved as a duplicate of SR-920

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

No branches or pull requests

3 participants