Re: [swift-users] FloatingPoint/BinaryFloatingPoint protocol and concrete FloatingPoint types

2017-12-01 Thread David Sweeris via swift-users


> On Dec 1, 2017, at 13:18, Jens Persson via swift-users 
>  wrote:
> 
> func maxPrecisionCalculation(input:Float80) -> Float80 {
> return input // but something actually reauiring high precision ...
> }

AFAIK, Float80 is the high precision format on macOS (well, Intel macs, 
anyway... can’t recall if Swift can target OSs old enough to run on PPC macs). 
I’d avoid using it, though. AFAIK it’s an x86-only format (it might even be 
Intel-only... 5-10 minutes of googling didn’t give me a clear answer on whether 
AMD’s CPUs support it).

I don’t know what we do with it on ARM targets, and I’m not at my computer to 
try to figure out.

Unless maybe the x86 or ARM vector extensions support 128 or 256 bit floats? I 
don’t think they do, but I’m not 100% on that.

- Dave Sweeris___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] FloatingPoint/BinaryFloatingPoint protocol and concrete FloatingPoint types

2017-12-01 Thread Jens Persson via swift-users
protocol Float80Convertible : BinaryFloatingPoint {
init(_ value: Float80)
var float80: Float80 { get }
}
extension Double : Float80Convertible {
var float80: Float80 { return Float80(self) }
}
extension Float : Float80Convertible {
var float80: Float80 { return Float80(self) }
}

func maxPrecisionCalculation(input:Float80) -> Float80 {
return input // but something actually reauiring high precision ...
}

func someComplexCalculation(input: T) -> T {
let input80 = input.float80
let output80 = maxPrecisionCalculation(input: input80)
return T(output80)
}


On Wed, Nov 29, 2017 at 12:45 PM, Antonino Ficarra via swift-users <
swift-users@swift.org> wrote:

> Suppose that I have a generic function that makes a complex floating
> calculation
> with a generic floating point type.
> Suppose that calculation require the max floating point machine precision
> so:
> 1) I need to convert the generic floating point type to Float80
> 2) make the complex calculation with Float80
> 3) convert back the Float80 result to the generic floating point type
>
>
> func maxPrecisionCalculation( input:Float80 ) -> Float80 {
> // 
> }
>
> Let's try with FloatingPoint:
>
> func someComplexCalculation( input:T ) -> T {
> let input80 = Float80( input ) // Error: Cannot invoke initializer for
> type 'Float80' with an argument list of type '(T)'
> let input80 = input as Float80 // Error 'T' is not convertible to
> 'Float80'; did you mean to use 'as!' to force downcast?
>
>
> let output80 = maxPrecisionCalculation( input:input80 )
>
>
> return output80 as T // Error: 'Float80' is not convertible to 'T'; did
> you mean to use 'as!' to force downcast?
> return T(output80) // Error: Non-nominal type 'T' does not support
> explicit initialization
> }
>
> How convert a generic FloatingPoint to a concrete floating point type and
> then convert it back?
>
> And now let's try with BinaryFloatingPoint:
>
> func someComplexCalculation ( input:T ) -> T {
>
> let input80 = Float80( input ) // Error: Cannot invoke initializer for
> type 'Float80' with an argument list of type '(T)'
> let input80 = input as Float80 // Error 'T' is not convertible to
> 'Float80'; did you mean to use 'as!' to force downcast?
>
>
> let output80 = maxPrecisionCalculation( input:Float80(0) )
>
>
> return T(output80) // Ok, now this work
> return output80 as T // Error: 'Float80' is not convertible to 'T'; did
> you mean to use 'as!' to force downcast?
> }
>
> How convert a generic BinaryFloatingPoint to a concrete floating
> point type?
> In the opposite direction the conversion work.
>
>
> NOTE: Using Double instead of Float80 don't make any difference at all.
>
> ADDENDUM: The Float80 type exists from the first Swift version. Now we
> have Swift 4
> and math function over Float80 are still unsupported, making this type
> substantially useless.
> I still can’t call sin(x) and log(x) with a Float80 value.
> There is a plan to resolve the issue?
>
>
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users