Math.sincos(x)?
Алексей
agat00 at gmail.com
Thu Jun 22 18:13:42 UTC 2017
If you think that performance of cos is too big (did you measure it?) than
just calculate cos from sin with the formula sin^2 + con^2 = 1
```js
function sincos (a) {
const sin = Math.sin(a)
const cos = (1 - sin**2)**0.5
return {sin, cos}
}
```
2017-06-22 21:02 GMT+03:00 Robert Poor <rdpoor at gmail.com>:
> [Preamble: this is my first post to es-discuss -- if this isn't the
> right place to suggest language extensions, please let me know.
> Thanks. - rdp]
>
> How often have you seen code that calls Math.sin() and Math.cos() with
> the same argument, e.g:
>
> x = r * Math.cos(theta);
> y = r * Math.sin(theta);
>
> ? This trope is repeated for polar coordinates, complex arithmetic, FTTs,
> etc.
>
> However, most implementations for cos(theta) actually generate
> sin(theta) as a "byproduct" (and vice-versa). Since trigonometric
> functions are relatively expensive, and this is a common pattern,
> wouldn't it make sense to define a function that returns cos(theta)
> and sin(theta) at the same time? A polyfill might look like this:
>
> function sincos(theta) {
> return { sin: sin(theta), cos: cos(theta) };
> }
>
> (or whatever the preferred style is for returning multiple values),
> but a real implementation would make a single call to the underlying
> trigonometric routine.
>
> - rdp
> _______________________________________________
> 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/20170622/02e5c98e/attachment-0001.html>
More information about the es-discuss
mailing list