<div dir="ltr"><div>On Mon, Nov 28, 2016 at 2:21 PM, Joe Groff via swift-users <span dir="ltr">&lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt;</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&#39;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">&lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt;</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>
&gt; On Nov 28, 2016, at 9:22 AM, Alex Blewitt via swift-users &lt;<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>&gt; wrote:<br>
&gt;<br>
&gt; 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>
&gt;<br>
&gt; <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>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; extension Decimal : ExpressibleByFloatLiteral {<br>
&gt;     public init(floatLiteral value: Double) {<br>
&gt;         self.init(value)<br>
&gt;     }<br>
&gt; }<br>
&gt;<br>
&gt; extension Decimal : ExpressibleByIntegerLiteral {<br>
&gt;     public init(integerLiteral value: Int) {<br>
&gt;         self.init(value)<br>
&gt;     }<br>
&gt; }<br>
<br>
</span>It really shouldn&#39;t be, since ExpressibleByFloatLiteral uses a binary float initial value and so doesn&#39;t guarantee decimal accuracy. I&#39;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>