Artoria2e5 / PRCoords

Public Domain library for rectifying Chinese coordinates
https://artoria2e5.github.io/PRCoords/demo.html
GNU General Public License v3.0
151 stars 23 forks source link

cpp: need nanobench #17

Closed Artoria2e5 closed 3 months ago

Artoria2e5 commented 4 months ago

I want to test some silly ideas about just swapping out sin(pi*x), but first we gotta know how to bench em. https://github.com/martinus/nanobench seems good.

(as to "what ideas": the pi multiplication offers very cheap range reduction for us. after that we're probably free to use Bhāskara and other cheap-ass stuff.

// what are you gonna do about it? x can't be too big!
inline double red4(double x){
    return fma(-round(x * 0.25), 4, x);
}
inline double sinpi_nick(double x) {
  x = red4(x * 2); // = 0 to 2pi; nick-magic works on units of 0.5pi
  double y = x * (2 - abs(x));
  return y * (0.775 + 0.225 * abs(y));
}
Artoria2e5 commented 3 months ago

done!