Swift.FloatingPointType needs toFloatMax() and from()

Originator:brent
Number:rdar://18173853 Date Originated:29-Aug-2014 03:34 AM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode6-Beta6 (6A280e)
Classification:Enhancement Reproducible:Always
 
Summary:
SignedIntegerType and UnsignedIntegerType have a mechanism to convert between their various types: all of them can be converted to, and constructed from, a 64-bit type, which is typealiased to IntMax or UIntMax. FloatingPointType should have a similar mechanism to convert via Float80.

Steps to Reproduce:
1. Declare a generic function (here, an operator) that converts between any two floating-point types:

    prefix func ^^ <FromFloat: FloatingPointType, ToFloat: FloatingPointType> (x: FromFloat) -> ToFloat {

2. Try to define it:

        return ToFloat.from(x.toFloatMax())

Expected Results:
You can.

Actual Results:
You can’t. This behavior is available on integers but not on floats.

Notes:
I encountered the need for this feature while trying to implement an explicit conversion operator. (The idea is, when you’re writing a math operation, you mark which operands should be converted, but let Swift infer the exact types it should convert them to.)

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!