<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">Suppose that I have a generic function that makes a complex floating calculation</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">with a generic floating point type.</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">Suppose that calculation require the max floating point machine precision so:</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">1) I need to convert the generic floating point type to Float80</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">2) make the complex calculation with Float80</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">3) convert back the Float80 result to the generic floating point type</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">func</span> maxPrecisionCalculation( input:<span style="color: #703daa" class="">Float80</span> ) -> <span style="color: #703daa" class="">Float80</span> {</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class=""><span class="Apple-tab-span" style="white-space:pre">        </span></span>// ....</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">}</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">Let's try with FloatingPoint:</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">func</span> someComplexCalculation<T:<span style="color: #703daa" class="">FloatingPoint</span>>( input:<span style="color: #4f8187" class="">T</span> ) -> <span style="color: #4f8187" class="">T</span> {</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><span style="font-family: Menlo; font-size: 13px;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span></span><span style="font-family: Menlo; font-size: 13px; color: rgb(186, 45, 162);" class="">let</span><span style="font-family: Menlo; font-size: 13px;" class=""> input80<span class="Apple-tab-span" style="white-space:pre">        </span>= </span><span style="font-family: Menlo; font-size: 13px; text-decoration: underline; color: rgb(112, 61, 170);" class="">F</span><span style="font-family: Menlo; font-size: 13px; color: rgb(112, 61, 170);" class="">loat80</span><span style="font-family: Menlo; font-size: 13px;" class="">( input )<span class="Apple-tab-span" style="white-space:pre">        </span></span><span style="color: rgb(0, 132, 0); font-family: Menlo; font-size: 13px;" class="">// Error: Cannot invoke initializer for type 'Float80' with an argument list of type '(T)'</span></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class=""><span class="Apple-tab-span" style="white-space:pre">        </span></span><span style="color: #ba2da2" class="">let</span><span style="color: #000000" class=""> </span><span style="text-decoration: underline ; color: #000000" class="">i</span><span style="color: #000000" class="">nput80 <span class="Apple-tab-span" style="white-space:pre">        </span>= input </span><span style="text-decoration: underline ; color: #ba2da2" class="">a</span><span style="color: #ba2da2" class="">s</span><span style="color: #000000" class=""> </span><span style="color: #703daa" class="">Float80</span><span style="color: #000000" class=""><span class="Apple-tab-span" style="white-space:pre">                </span></span>// Error 'T' is not convertible to 'Float80'; did you mean to use 'as!' to force downcast?</div><p style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255); min-height: 15px;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span><br class="webkit-block-placeholder"></p><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span style="color: #ba2da2" class="">let</span> output80<span class="Apple-tab-span" style="white-space:pre">        </span>= <span style="color: #31595d" class="">maxPrecisionCalculation</span>( input:input80 )</div><p style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255); min-height: 15px;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span><br class="webkit-block-placeholder"></p><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class=""><span class="Apple-tab-span" style="white-space:pre">        </span></span><span style="color: #ba2da2" class="">return</span><span style="color: #000000" class=""> output80 </span><span style="color: #ba2da2" class="">as</span><span style="color: #000000" class=""> </span><span style="color: #4f8187" class="">T</span><span style="color: #000000" class=""> <span class="Apple-tab-span" style="white-space:pre">        </span></span>// Error: 'Float80' is not convertible to 'T'; did you mean to use 'as!' to force downcast?</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class=""><span class="Apple-tab-span" style="white-space:pre">        </span></span><span style="color: #ba2da2" class="">return</span><span style="color: #000000" class=""> </span><span style="color: #4f8187" class="">T</span><span style="color: #000000" class="">(output80)<span class="Apple-tab-span" style="white-space:pre">        </span></span>// Error: Non-nominal type 'T' does not support explicit initialization</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">}</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">How convert a generic FloatingPoint to a concrete floating point type and then convert it back?</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><span style="font-family: Menlo; font-size: 13px;" class="">And now let's try with BinaryFloatingPoint:</span></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class=""><br class=""></span></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">func</span> someComplexCalculation <T:<span style="color: #703daa" class="">BinaryFloatingPoint</span>>( input:<span style="color: #4f8187" class="">T</span> ) -> <span style="color: #4f8187" class="">T</span> {</div><p style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255); min-height: 15px;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span style="color: rgb(186, 45, 162);" class="">let</span> input80<span class="Apple-tab-span" style="white-space:pre">        </span>= <span style="text-decoration: underline; color: rgb(112, 61, 170);" class="">F</span><span style="color: rgb(112, 61, 170);" class="">loat80</span>( input )<span class="Apple-tab-span" style="white-space:pre">        </span><span style="color: rgb(0, 132, 0);" class="">// Error: Cannot invoke initializer for type 'Float80' with an argument list of type '(T)'</span></p><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class=""><span class="Apple-tab-span" style="white-space:pre">        </span></span><span style="color: #ba2da2" class="">let</span><span style="color: #000000" class=""> </span><span style="text-decoration: underline ; color: #000000" class="">i</span><span style="color: #000000" class="">nput80 <span class="Apple-tab-span" style="white-space:pre">        </span>= input </span><span style="text-decoration: underline ; color: #ba2da2" class="">a</span><span style="color: #ba2da2" class="">s</span><span style="color: #000000" class=""> </span><span style="color: #703daa" class="">Float80</span><span style="color: #000000" class=""><span class="Apple-tab-span" style="white-space:pre">        </span></span>// Error 'T' is not convertible to 'Float80'; did you mean to use 'as!' to force downcast?</div><p style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255); min-height: 15px;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span><br class="webkit-block-placeholder"></p><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span style="color: #ba2da2" class="">let</span> output80<span class="Apple-tab-span" style="white-space:pre">        </span>= <span style="color: #31595d" class="">maxPrecisionCalculation</span>( input:<span style="color: #703daa" class="">Float80</span>(<span style="color: #272ad8" class="">0</span>) )</div><p style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255); min-height: 15px;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span><br class="webkit-block-placeholder"></p><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class=""><span class="Apple-tab-span" style="white-space:pre">        </span></span><span style="color: #ba2da2" class="">return</span><span style="color: #000000" class=""> </span><span style="color: #4f8187" class="">T</span><span style="color: #000000" class="">(output80)<span class="Apple-tab-span" style="white-space:pre">        </span></span>// Ok, now this work</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class=""><span class="Apple-tab-span" style="white-space:pre">        </span></span><span style="color: #ba2da2" class="">return</span><span style="color: #000000" class=""> output80 </span><span style="text-decoration: underline ; color: #ba2da2" class="">a</span><span style="color: #ba2da2" class="">s</span><span style="color: #000000" class=""> </span><span style="color: #4f8187" class="">T</span><span style="color: #000000" class=""> <span class="Apple-tab-span" style="white-space:pre">        </span></span>// Error: 'Float80' is not convertible to 'T'; did you mean to use 'as!' to force downcast?</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">}</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">How convert a generic BinaryFloatingPoint to a concrete floating point type?</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">In the opposite direction the conversion work.</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">NOTE: Using Double instead of Float80 don't make any difference at all.</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">ADDENDUM: The Float80 type exists from the first Swift version. Now we have Swift 4</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">and math function over Float80 are still unsupported, making this type substantially useless.</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">I still can’t call sin(x) and log(x) with a Float80 value.</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">There is a plan to resolve the issue?</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div></body></html>