On Apr 24, 10:37 am, Riccardo De Agostini wrote:
<snip>
>     function Sine_easeIn(t)
>     {
>         return -1 * Math.cos(t * (Math.PI / 2)) + 1;
>     }

It is an underappreciated characteristic of ECMAScript that the
language does not contain such a thing as a negative numeric literal.
Instead constructs such as the "-1" above represent the unary negation
operator being applied to the positive numeric literal one. So
theoretically "-1" implies a runtime operation, though it is certainly
possible that an ECMAScript implementation could treat it as a
negative numeric literal (as doing so would not change the behaviour
of the code) and so only act on the "-" while compiling the code.

In any event, the expression "-1 * x" should always have the same
outcome as the expression "-x" and the latter would be one fewer
operations in ECMAScript terms (and even if the -1 is treated as a
negative numeric literal the unary negation operation should be faster
than the multiplication). Granted there won't be much in it
(especially against the unavoidable overheads of the function call),
but why not.

>     function Sine_easeOut(t)
>     {
>         return 1 * Math.sin(t * (Math.PI / 2));
>     }
<snip>

I cannot see any reason for multiplying any number by positive one.
That operation is sometimes used to force type-conversion (to numeric)
but that cannot be the reason here as the return value from - Math.sin
- is already guaranteed to be numeric.

There are (inevitably) a number of uses of - Math.PI * 2 - and -
Math.PI / 2 - in this code. It might be an idea to assign these two
values to variables in the containing scope and employ them as
constants in the functions. Apart from not repeating the math
operations each time they are used, the scope-chain lookup of the
variables should never be slower than the scope-chain lookup of - Math
- and so certainly will be faster than resolving - Math.PI -.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to