[swift-evolution] Missing initializers from/to FloatingPointType
Stephen Canon
scanon at apple.com
Thu Apr 7 13:17:52 CDT 2016
The draft proposal may be easier reading:
https://github.com/stephentyrone/swift-evolution/blob/master/NNNN-floating-point-protocols.md
> On Apr 7, 2016, at 11:16 AM, Max Moiseev via swift-evolution <swift-evolution at swift.org> wrote:
>
> Hi Dan,
>
> New protocols are in the making for both integers and floating point numbers.
>
> You particular problem is addressed here: https://github.com/stephentyrone/swift/commits/floating-point-revision <https://github.com/stephentyrone/swift/commits/floating-point-revision>
>
> max
>
>> On Mar 30, 2016, at 6:36 AM, Dan Raviv via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>
>> 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?
>>
>> I've tried implementing the following:
>>
>> // https://en.wikipedia.org/wiki/Window_function#Tukey_window <https://en.wikipedia.org/wiki/Window_function#Tukey_window>
>> public func tukeyWindowFunc(index: Int, N: Int) -> Double {
>> let L = N/8
>> let indexAbs = min(index, N-1-index)
>> if indexAbs >= L {
>> return 1.0
>> }
>> else {
>> let r = Double(indexAbs) / Double(L)
>> return 0.5*(1.0 + cos(M_PI * (r - 1.0)))
>> }
>> }
>>
>> extension Array where Element: FloatingPointType {
>> public func tukeyWindowArray() -> [Element] {
>> return (0..<count).map{self[$0] * tukeyWindowFunc($0, N: count)}
>> }
>> }
>>
>> 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.
>>
>> I would settle for extending just Array<Double>, but that isn't supported yet either ;)
>>
>> Cheers,
>> Dan
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160407/13a25830/attachment.html>
More information about the swift-evolution
mailing list