[swift-evolution] [Proposal draft] Enhanced floating-point protocols
scanon at apple.com
Fri Apr 15 13:22:40 CDT 2016
> On Apr 15, 2016, at 11:14 AM, Erica Sadun <erica at ericasadun.com> wrote:
> On Apr 15: 2016: at 11:56 AM: Joe Groff via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>> On Apr 15: 2016: at 8:20 AM: Stephen Canon via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>> “e” is a great bike-shedding example. While it would definitely allow a fluent style if you know what you’re looking at: I worry a little bit about readability of `Float.e` or `.e` in source. Most programmers are at least passingly familiar with pi: but that familiarity doesn’t necessarily extend to e. IDEs and docstrings make this palatable: of course.
>> It's also questionable to me how often `e` itself is interesting independent of an exp() or log() operation.
> I'm sure it gets used but I'd imagine it would be at an order of magnitude or more less than PI. Quick gist count:
> M_E: 109
> M_LOG2E: 23
> M_LOG10E: 19
> M_LN2: 24
> M_LN10: 10
> M_PI: 2,231
> M_PI_2: 255
> M_PI_4: 54
> M_1_PI: 27
> M_2_PI: 25
> M_2_SQRTPI: 23
> M_SQRT2: 31
> M_SQRT1_2: 26
> That said, I use M_PI_4 a lot because it's really handy for sample code. I'm one of the
> outlier users whose use is not reflective of this quick check.
M_PI_2 and M_PI_4 are interesting cases; they date back to a time when compilers couldn’t be trusted to constant-fold computations like M_PI / 2. Since Swift quite reliably does this transformation, I would prefer to simply use the more explicit .pi / 2. How does that strike you as a user?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution