<div dir="ltr"><div>On Mon, Nov 28, 2016 at 2:21 PM, Joe Groff via swift-users <span dir="ltr"><<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>></span> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">ExpressibleByFloatLiteral uses a binary float initial value and so doesn't guarantee decimal accuracy</blockquote><div class="gmail_extra"><br></div><div class="gmail_extra">That seems like a flaw in ExpressibleByFloatLiteral that should be fixed.</div><div class="gmail_extra"><br></div><div class="gmail_extra">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?</div><div class="gmail_extra"><br></div><div class="gmail_extra">Nevin</div><div class="gmail_extra"><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Nov 28, 2016 at 2:21 PM, Joe Groff via swift-users <span dir="ltr"><<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-"><br>
> On Nov 28, 2016, at 9:22 AM, Alex Blewitt via swift-users <<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>> wrote:<br>
><br>
> NSDecimal conforms to the ExpressibleBy(Float|Integer)<wbr>Literal, but that just means it can be created from a literal value, not the other way around:<br>
><br>
> <a href="https://github.com/apple/swift-corelibs-foundation/blob/108a5b0006912c6cf6b59e4954255237bf01b67a/Foundation/NSDecimal.swift#L319-L329" rel="noreferrer" target="_blank">https://github.com/apple/<wbr>swift-corelibs-foundation/<wbr>blob/<wbr>108a5b0006912c6cf6b59e49542552<wbr>37bf01b67a/Foundation/<wbr>NSDecimal.swift#L319-L329</a><br>
><br>
><br>
><br>
> extension Decimal : ExpressibleByFloatLiteral {<br>
> public init(floatLiteral value: Double) {<br>
> self.init(value)<br>
> }<br>
> }<br>
><br>
> extension Decimal : ExpressibleByIntegerLiteral {<br>
> public init(integerLiteral value: Int) {<br>
> self.init(value)<br>
> }<br>
> }<br>
<br>
</span>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:<wbr>isNegative:) instead, and minimizing any conversions between Double and Decimal.<br>
<br>
-Joe<br>
<div class="gmail-HOEnZb"><div class="gmail-h5">______________________________<wbr>_________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-users</a><br>
</div></div></blockquote></div><br></div></div>