Skip to content

Theoretically exact sine/cosine method #19

@nslay

Description

@nslay

Very cool library! I found it mentioned in a constexpr stackexchange question. I like to dabble with low level math like this and I've derived a theoretically exact way to calculate sine/cosine by playing games with the half-angle formulae and bits. I've provided the derivation and a (probably poorly written) C++14 constexpr version (requires constexpr abs, sqrt, sgn, and modf). You might already know this trickery. I can't promise the C++14 version is correct (Clang 6 is happy with it) or if MSVC will tolerate it.

I'm not suggesting you use this. Your implementation using Taylor series (if I'm not mistaken) is probably a lot faster since this formulation needs to examine at most the number of mantissa bits (e.g. 52 for double precision)!

I think there is a name for this method. I don't remember off the top of my head. But good fun!

Thanks for the library!

Here's the demo code... I can just use your static math library from now on!
demo.txt

And below are notes I wrote myself if I ever look at this code again in the distant future.

NOTE: I didn't intend for the LaTeX pictures to automatically display.

Explanation
explanation

Pseudo Code
pseudocode

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions