Does webassembly have support for trig functions? I mean like built in support because it seems we have to import those from javascript. It would be great if we had things like:
f32.sin
f32.cos
If it makes any sense. If they dont exist I assume its because the implementation is very system dependent.
The problem:
Imagine we had some really complex and computationally expensive formula which involves these math functions. I would like to compute everything in webassembly without relying on imports or subdividing my code where one part is run in webassembly and the other in javascript.
Apart from that I do believe semantically things look neater if trig functions were built in.
Trigonometric functions aren't available in WebAssembly though it's been discussed before 1, 2, 3. In general, WebAssembly provides opcodes for things that exist efficiently as CPU instructions, and trigonometric functions just don't have efficient CPU versions nowadays (even the x86 sin / cos is slow).
Further, we don't want to mandate specific precision bounds at this point in time. It's an art-form to specify trigonometric functions with the right precision and there hasn't been strong interest thus far.
In the future, we'd like to see code sharing of something like libm.wasm, which would remove the code download burden.
An argument could be made that implementations could be more efficient if one had ISA information, but we'd need someone championing that usecase with data to standardize it. I expect the first such case to be fast sqrt and inverse sqrt approximations, which are often used in games and do have good ISA support. I haven't heard of real performance-sensitive trigonometric uses otherwise in the context of WebAssembly. Not that I don't think they'd exist: it's a simple question of priorities for the Community Group.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With