Swift: Type generic math functions

Originator:zwaldowski
Number:rdar://17474955 Date Originated:06/26/2014
Status:Duplicate Resolved:false
Product:Developer Tools Product Version:Xcode 6.0 Developer Preview 2/6A216f; Swift version 1.0/600.0.34.4.8
Classification:Enhancement Reproducible:Always
 
Swift bridges with the C stdlib math functions directly, which is workable. However, the lack of type-safe generic math functions makes doing type-ambiguous math work extremely difficult - particularly when ambiguous types, like CoreGraphics' CGFloat is in play.

Steps to reproduce:
1. Set up an iOS project.
2. In any view/layer/UIKit-related class, set up some frame math
3. Make the unfortunate decision to round/floor/ceil
4. Add Double() or Float() casts to make builds succeed
5. Switch to the opposite bit-width platform/simulator target
6. Add Double() or Float() casts to make builds succeed
7. Switch to the opposite bit-width platform/simulator target
8. Repeat... 

Expected results:
Swift supports function overloading; overloaded math functions should exist that supplant the Darwin.C.math and Darwin.C.tgmath ones, as in C++.

Actual results:
A developer is required to choose between, for example, floor and floorf and aggressively cast/initialize new Double() or Float(), and the "casts" that worked to make one platform compile will not work on another.

Configuration:
Occurs primarily when building an application in Swift that targets both 32-bit and 64-bit platforms simultaneously.

Additional Notes:
Using Darwin.C.tgmath's __tg_floor et. al. produces linker errors, as the Swift compiler refuses to inline the tgmath functions from the Clang stdlib's header.

Comments

Engineering has determined that your bug report (17474955) is a duplicate of another issue (17199880) and will be closed.

The open or closed status of the original bug report your issue was duplicated to appears in the yellow "Duplicate of XXXXXXXX" section of the bug reporter user interface. This section appears near the top of the right column's bug detail view just under the bug number, title, state, product and rank.

By zwaldowski at July 1, 2014, 12:54 p.m. (reply...)

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!