[swift-evolution] [Pitch] Angle Type

Erica Sadun erica at ericasadun.com
Tue Jan 16 10:00:43 CST 2018

> On Jan 15, 2018, at 2:40 PM, Stephen Canon via swift-evolution <swift-evolution at swift.org> wrote:
>> On Jan 15, 2018, at 4:31 PM, Karl Wagner via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>> On 14. Jan 2018, at 21:12, Kelvin Ma via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>> This could work, but you’re also giving up all the nice Numeric and FloatingPoint conformances when you use this,, all of a sudden adding two angles together isn’t let γ = α + β, it’s γ = Angle.radians(α.radians + β.radians). just no. at the risk of blowing up the scope of this idea, dedicated Angle types also begs for generic trigonometric functions like Angle.sin(_:) and Angle.cos(_:). i proposed that a while back and even tried implementing it but fast trig evaluation doesn’t genericize well since it relies a lot on rsqrt-style magic constants
>> You could add those conformances back, if you wanted. Most low-level trig code will quickly escape the wrapper once it starts using the values. Mostly I use it as a currency type and for converting untyped angles. I think it’s a great example of Swift’s zero-cost abstractions - we added semantic meaning (this value isn’t just a number with a specific bit representation, it’s a number which represents a specific kind of quantity), and encapsulated some useful functionality, and we don't lose any performance.
> And in fact you probably don’t want that conformance. It makes sense dimensionally to add two angles. It doesn’t (generally) make as much sense to multiply them, or to take the square root of an angle. I would expect an angle type to provide + and - but probably not * and / and most of the other floating-point operations.
> – Steve

This is getting way off topic for Evolution but I'd like to point out that `angle * factor` and `angle / factor ` both make sense. Maybe we should take this conversation over to some kind of ad-hoc Swift Geometry forum?

-- E

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20180116/0897ed65/attachment.html>

More information about the swift-evolution mailing list