I went through the same exercise implementing trig functions for scheme in webassembly...
It was a rabbit hole for sure
https://github.com/PollRobots/scheme/blob/main/scheme.wasm/s...
[Edit: above is just the range from 0-π/4, the branch cuts for cos are at https://github.com/PollRobots/scheme/blob/main/scheme.wasm/s... ]