Morwenn / static_math

Compile time mathematic functions for C++14
MIT License
187 stars 22 forks source link

Self-modifying operators for constexpr complex and imaginary #7

Closed kundor closed 8 years ago

kundor commented 8 years ago

In C++14, constexpr evaluations can modify variables, so it's nice to have compile-time classes which can be manipulated.

I wrote a compile-time polynomial class, and I wanted to use it with complex coefficients. Unfortunately, std::complex does not have constexpr operators, so I couldn't use it.

To use smath::complex instead, the member variables should not be const, and it's handy to have the self-assigning operators. This PR adds those.

I also added a polar function (like std::polar, except constexpr.)

Thanks.

Morwenn commented 8 years ago

Uh, it's true that this library is a bit rusty and its original design choices when it was still C++11-only couldn't take into account C++14's enhanced constexpr. Now could be a good time to change that.

Anyway, thanks for your pull request, I will review it tonight (UTC+1). Apparnetly it looks mostly fine, so you can expect it to be merged soon enough :)

Morwenn commented 8 years ago

I merged your pull request and then added more things to complex and imaginary even though they're still a bit incomplete. Some things might break your code, most notably the constructor to construct an imaginary from a real value has been made explicit for obvious reasons. If anything else breaks your code, don't hesitate to submit an issue.

Thanks again for your additions!