<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Hi Dan,</div><div class=""><br class=""></div><div class="">New protocols are in the making for both integers and floating point numbers.</div><div class=""><br class=""></div><div class="">You particular problem is addressed here: <a href="https://github.com/stephentyrone/swift/commits/floating-point-revision" class="">https://github.com/stephentyrone/swift/commits/floating-point-revision</a></div><div class=""><br class=""></div><div class="">max</div><br class=""><div><blockquote type="cite" class=""><div class="">On Mar 30, 2016, at 6:36 AM, Dan Raviv via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">While FloatingPointType can be initialized from various Int type variants, it seems to be missing an initializer from Double/Float. Similarly, there are no initializers from FloatingPointType to Double/Float. Is this intentional?<br class=""><br class="">I've tried implementing the following:<br class=""><br class="">// <a href="https://en.wikipedia.org/wiki/Window_function#Tukey_window" class="">https://en.wikipedia.org/wiki/Window_function#Tukey_window</a><div class="">public func tukeyWindowFunc(index: Int, N: Int) -&gt; Double {<br class="">&nbsp; &nbsp; let L = N/8<br class="">&nbsp; &nbsp; let indexAbs = min(index, N-1-index)<br class="">&nbsp; &nbsp; if indexAbs &gt;= L {<br class="">&nbsp; &nbsp; &nbsp; &nbsp; return 1.0<br class="">&nbsp; &nbsp; }<br class="">&nbsp; &nbsp; else {<br class="">&nbsp; &nbsp; &nbsp; &nbsp; let r = Double(indexAbs) / Double(L)<br class="">&nbsp; &nbsp; &nbsp; &nbsp; return 0.5*(1.0 + cos(M_PI * (r - 1.0)))<br class="">&nbsp; &nbsp; }<br class="">}<br class=""><br class="">extension Array where Element: FloatingPointType {<br class="">&nbsp; &nbsp; public func tukeyWindowArray() -&gt; [Element] {<br class="">&nbsp; &nbsp; &nbsp; &nbsp; return (0..&lt;count).map{self[$0] * tukeyWindowFunc($0, N: count)}<br class="">&nbsp; &nbsp; }<br class="">}<br class=""><br class="">The extension failed to compile no matter how I spun it, since Double and FloatingPointType can't multiply each other and neither type can be cast to the other.<div class=""><br class=""></div><div class="">I would settle for extending just Array&lt;Double&gt;, but that isn't supported yet either ;)</div><div class=""><br class=""></div><div class="">Cheers,</div><div class="">Dan</div></div></div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>