[swift-evolution] TrigonometricFloatingPoint/MathFloatingPoint protocol?

Taylor Swift kelvin13ma at gmail.com
Mon Jul 31 12:26:08 CDT 2017


On Mon, Jul 31, 2017 at 1:19 PM, Benjamin Spratling <bspratling at mac.com>
wrote:

> 1) Why would cos, sin, ln, tan, asin, acos, atan and  exp be functions and
> not computed properties?
> 2) For people who uses these features on paper and text books, writing
> them as what we call global functions is standard.  Seeing them the same in
> both places reduces the translation they must do, and thus reduces
> accidental errors, and reduces the difficulty of reading and validating
> code.
>
> -Ben
>

My first thought was to have them as free functions, but the trend in the
Swift stdlib seems to be to go with namespaced protocol methods. For
example, squareRoot() and signum() are methods, not toplevel functions. (I
have no idea why abs() is a free function though.) Also, as to why they are
functions and not computed properties, I would have suggested making them
computed properties but I believe there was a big fuss a while back about
why signum() had to be a method and not a property so I’m just going off of
that.


>
> Sent from my iPhone.
>
> > On Jul 31, 2017, at 1:03 PM, Taylor Swift via swift-evolution <
> swift-evolution at swift.org> wrote:
> >
> > How would people feel about adding a protocol
> >
> > protocol MathFloatingPoint:FloatingPoint
> > {
> >     func sin() -> Self
> >     func cos() -> Self
> >     func tan() -> Self
> >     func asin() -> Self
> >     func acos() -> Self
> >     func atan() -> Self
> >
> >     func ln() -> Self
> >     func log(base:Self) -> Self
> >     func pow(exponent:Self) -> Self
> >     func exp() -> Self
> > }
> >
> > to the standard library? Float and Double would then be made to conform
> by default using Swift implementations instead of having to import Glibc /
> Darwin and writing the extensions, depending on platform.
> > _______________________________________________
> > swift-evolution mailing list
> > swift-evolution at swift.org
> > https://lists.swift.org/mailman/listinfo/swift-evolution
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170731/6c1a1fcf/attachment.html>


More information about the swift-evolution mailing list