grain-lang / grain

The Grain compiler toolchain and CLI. Home of the modern web staple. 🌾
https://grain-lang.org/
GNU Lesser General Public License v3.0
3.26k stars 113 forks source link

feat(stdlib): Reimplement `Number.sin`, `Number.cos`, `Number.tan` #2158

Closed spotandjake closed 1 week ago

spotandjake commented 2 weeks ago

This pr reintroduces Number.sin after it was removed in #2046, this uses the implementation found in libc, with some adaptations made for wasm and grain. It uses a small kernal function that accuratly can compute sin for values between -pi/4 to pi/4 and a range reduction algorithm to map any values outside the range into the range efficently.

Notes:

Although I ported the argument reduction algorithm if anyone wants to better understand it here is a link: https://userpages.cs.umbc.edu/phatak/645/supl/Ng-ArgReduction.pdf to a paper on a similar algorithm.

work for #1478

spotandjake commented 1 week ago

Made that change