[Swift] Provide overloaded functions for float/double functions in C
| Originator: | herzberg.sven | ||
| Number: | rdar://17654929 | Date Originated: | 2014-07-13 |
| Status: | Open | Resolved: | |
| Product: | iOS SDK | Product Version: | XCode 6 Beta 3 |
| Classification: | Enhancement | Reproducible: | Always |
Summary: By using type inference and method overloading, CGFloat will be a lot easier to handle with 64bit compatibility. Steps to Reproduce: To compute the distance between two CGPoint instances, it is useful to use hypot()/hypotf() from <math.h>. Right now, one has to write this code to make sure both 32bit and 64bit builds work well: I want to calculate the distance between two CGPoint with hypot(): let distance : CGFloat = hypot(from.x - to.x, from.y - to.y) Expected Results: There are two overloaded global functions called “hypot()”: func hypot (x: Double, y: Double) -> Double func hypot (x: Float, y: Float) -> Float Using type inference and overloaded methods like these, the difference between 64bit and 32bit architectures will blur and be a lot easier to manage. Actual Results: People have to create their own wrappers to make sure, they don't have to spread 32bit-vs-64-bit code everwhere in the code base. #if arch(arm64) let my_hypot : (CGFloat, CGFloat) -> CGFloat = hypot #else let my_hypot : (CGFloat, CGFloat) -> CGFloat = hypotf #endif Notes: This also applies to several other functions such as sin/sinf, cos/cosf, etc.
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!