The sin() and cos() functions seem to be using some kind of lookup table at ¼ the number resolution, with clamping. It is easy to use linear interpolation instead and improve the precision of these functions by calling them twice:
function trig(f,x) local a, b = f(x & 0x.fffc), f(x | 0x.0003) return a + (b - a) * (x << 14 & 0x.c) end function xsin(x) return trig(sin,x) end function xcos(x) return trig(cos,x) end |
@zep I think PICO-8 could very well do this internally, as the extra cost seems negligible. The same goes with atan2(), especially since in that case it is significantly more difficult to do in PICO-8 user land.
Great idea! Do you mind if I use this in https://github.com/sparr/pico8lib ?
[Please log in to post a comment]