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

David Sweeris davesweeris at mac.com
Sun Dec 3 18:14:12 CST 2017


Sorry, mostly I was just commenting on what I now see was an incorrect interpretation of the “// but something actually requiring high precision ...” comment in your example code. I’d read it as... you know, I’m not sure what I’d though it said... I think something that implied the code would convert the `Float80` data to another format with higher precision.

My mistake for not reading more carefully before replying.

- Dave Sweeris 

> On Dec 3, 2017, at 15:22, Jens Persson <jens at bitcycle.com> wrote:
> 
> I'm not sure what you mean David. That function was just part of my attempt at presenting a solution to Antonino's question (that particular function is from Antonino's code).
> Below is my solution to Antonino's problem again, including a perhaps clearer comment in that function:
> 
> 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 inpu
>     // In the actual use case, this would of course not just
>     // return input. Instead it would perform some computation
>     // that (in contrast to just returning input) actually needs
>     // the high precision of Float80.
> }
> 
> func someComplexCalculation<T:Float80Convertible>(input: T) -> T {
>     let input80 = input.float80
>     let output80 = maxPrecisionCalculation(input: input80)
>     return T(output80)
> }
> 
> /Jens
> 
> 
>> On Fri, Dec 1, 2017 at 11:59 PM, David Sweeris <davesweeris at mac.com> wrote:
>> 
>> 
>>> On Dec 1, 2017, at 13:18, Jens Persson via swift-users <swift-users at swift.org> 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
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20171203/6d814e98/attachment.html>


More information about the swift-users mailing list