[swift-evolution] Missing initializers from/to FloatingPointType

Dan Raviv dan.raviv at gmail.com
Wed Mar 30 08:36:16 CDT 2016

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

I've tried implementing the following:

// 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 ;)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160330/132ce433/attachment.html>

More information about the swift-evolution mailing list