On Mon, Nov 28, 2016 at 2:21 PM, Joe Groff via swift-users < swift-users@swift.org> wrote:
> ExpressibleByFloatLiteral uses a binary float initial value and so doesn't > guarantee decimal accuracy That seems like a flaw in ExpressibleByFloatLiteral that should be fixed. Did anyone ever submit a proposal following the discussion in “[swift-evolution] Allow FloatLiteralType in FloatLiteralConvertible to be aliased to String” where somebody—*runs to check*…oh it was you!—described the proper solution? Nevin On Mon, Nov 28, 2016 at 2:21 PM, Joe Groff via swift-users < swift-users@swift.org> wrote: > > > On Nov 28, 2016, at 9:22 AM, Alex Blewitt via swift-users < > swift-users@swift.org> wrote: > > > > NSDecimal conforms to the ExpressibleBy(Float|Integer)Literal, but that > just means it can be created from a literal value, not the other way around: > > > > https://github.com/apple/swift-corelibs-foundation/blob/ > 108a5b0006912c6cf6b59e4954255237bf01b67a/Foundation/ > NSDecimal.swift#L319-L329 > > > > > > > > extension Decimal : ExpressibleByFloatLiteral { > > public init(floatLiteral value: Double) { > > self.init(value) > > } > > } > > > > extension Decimal : ExpressibleByIntegerLiteral { > > public init(integerLiteral value: Int) { > > self.init(value) > > } > > } > > It really shouldn't be, since ExpressibleByFloatLiteral uses a binary > float initial value and so doesn't guarantee decimal accuracy. I'd > recommend using init(mantissa:exponent:isNegative:) instead, and > minimizing any conversions between Double and Decimal. > > -Joe > _______________________________________________ > swift-users mailing list > swift-users@swift.org > https://lists.swift.org/mailman/listinfo/swift-users >
_______________________________________________ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users