Math.TAU

A Matías Quezada amatiasq at gmail.com
Wed Jul 2 08:52:11 PDT 2014


This is not a character-count issue, neither a "is mathematically
calculable" issue. It's a readability and maintainability issue. When
developing games we have 3 options:

 1. Use Math.PI * 2 everywhere
 2. Create a TAU constant on every file
 3. Create a TAU constant on a single file and require this file from
everywhere just for this

For readability I should choose the second one, for maintainability the
third one, if it's on Math it's both maintainable and readable. This kind
of problems creates distractions when creating a game.

I don't see the problem, it's a simple solution for a recurrent issue.

---
A. Matías Quezada
Senior Javascript Developer
amatiasq at gmail.com



2014-07-02 11:14 GMT+02:00 Alex Kocharin <alex at kocharin.ru>:

>
> If writing 'foo'.startsWith('foo') instead of 'foo'.indexOf('foo')==0
> worth extending String's prototype (which IS a big deal), another math
> constant is worth it (since it is actually useful, see Rick's googling
> results).
>
> If javascript was a language with tiny api, yes, your argument will hold.
> But currently includes anything more or less useful for programmer's
> convenience, and since Math utils becoming more important (people start to
> write complex math in it which was impossible a few years ago due to
> performance... is webgl in use already?), adding tau is well worth it.
>
> > Remembering that PI*2 is TAO is required to even make use of it,
> unless/until mathematicians, books, and wikipedia start using TAO where 2
> PI is currently used, you have to convert them.
>
> Nope. It is the length of the unit circle, end of story. I don't need to
> remember what is it to start writing `if (x >= Math.TAU) x -= Math.TAU` for
> boundary check for example.
>
> Also... it TAU, not TAO. If you don't know what it is and use 2*PI all
> over the place, of course it won't be useful for you. But it doesn't mean
> that it's silly.
>
>
> 01.07.2014, 04:26, "Frankie Bagnardi" <f.bagnardi at gmail.com>:
>
> String.prototype.endsWith and Object.is are functions, and their JS
> implementations are nontrivial to memorize and type (although not the worst
> examples).  Memorizing PI to more than a few digits is nontrivial.  Same
> with Math.E, or Math.atan2, or most of the other Math functions and
> properties.
>
> Remembering that PI*2 is TAO is required to even make use of it,
> unless/until mathematicians, books, and wikipedia start using TAO where 2
> PI is currently used, you have to convert them.  So if you decide to used
> it, you already know the definition.  The alternative to other things in
> JavaScript (for the most part) spending time researching how to implement
> it, comparing existing implementations, or having to look up a constant
> value (e.g. 3.141592653589793).
>
> Seems a little silly, and I'd rather see some of the use cases for it end
> up on Math if anything.
>
>
> On Mon, Jun 30, 2014 at 4:55 PM, Alex Kocharin <alex at kocharin.ru> wrote:
>
>
>
> 30.06.2014, 21:09, "C. Scott Ananian" <ecmascript at cscott.net>:
>
> On Mon, Jun 30, 2014 at 1:01 PM, Rick Waldron <waldron.rick at gmail.com>
> wrote:
>
> Just because other languages don't include a TAU constant doesn't mean
> ECMAScript cannot.
>
> Just because "serious mathematicians" think this is "crackpot territory",
> doesn't mean it's not useful (the condescension of that claim certainly
> isn't).
>
>
> As I mentioned, although I am a pi-ist, I think Math.TAU is harmless.  But
> I will qualify the "not useful" part -- there is no numerical accuracy
> benefit to using Math.TAU (only the floating point exponent changes), nor
> is there likely to be any emitted-code improvement (constant propagation
> being a standard part of any reasonable runtime).  So the benefit is solely
> the single character minimized code size improvement from '2*Math.PI' to
> 'Math.TAU' (if this were significant wouldn't the minimizers be assigning
> this to a single-character variable already?)
>
>
>
> It's not about code size or numerical accuracy. When developing HTML5
> games where a lot of trigonometric calculus takes place, I'm used to see
> 2*Math.PI more often than Math.PI by itself. People usually treat it as one
> single constant (which is prone to errors if someone writes 1/2*Math.PI
> instead of 1/(2*Math.PI)). It's just better to replace it with one constant
> than having this multiplication appear everywhere.
>
> So I'd like to see this make its way to the standard... it's certainly
> more useful than, say, String.prototype.endsWith or Object.is :)
>
> // alex
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140702/8da7d42e/attachment-0001.html>


More information about the es-discuss mailing list