Author Topic: Compact sin(x) which gets to within 0.1%, x = 0 to 2xPI  (Read 3240 times)

0 Members and 1 Guest are viewing this topic.

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 8330
  • Country: fr
Re: Compact sin(x) which gets to within 0.1%, x = 0 to 2xPI
« Reply #100 on: December 28, 2021, 07:14:08 pm »
Certainly easy enough to experiment...

I get the same results on this independent of ISA or gcc/clang.

Ahh, interesting that it simplifies 2, but not 3...

Ah, that makes sense, -funsafe-math-optimizations will generate the [naively] expected code (but it might not distribute errors exactly the way you like, hence the name of the option).  I suppose squaring being a binary operation (x * x), order doesn't matter, but for other powers it does.  Also works for negative powers (emitting a division op, and whatever muls to get it there).

Yeah. Of course, there is no hard rule about this at all and so it's 100% compiler-dependent. I would also expect it to support only a restricted range of functions and possible values.
I guess only if you use C++ "constexpr" can you be sure enough that what can be computed at compile-time will be and give the same result as it would during run time.

Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo