I'd like to utilize C++14's constexpr semantics expansion to calculate some mathematical formulae at compile time. But - I don't want to "roll my own" constexpr versions of sqrt(), log(), sin() etc. It's not that I couldn't do it, it's just that it would be reinventing the wheel.

So has anyone published such a library?


  • Must be platform-independent.
  • No Boost dependencies please.
  • It should be C++14-based; just C++11 would make for a rather contrived implementation.
  • Since we're talking about constexpr here, it should be portable and the hardware and OS details shouldn't really matter.
  • 1
    Need details of which platform, CPU, OS, etc., to possibly answer. Commented Feb 20, 2016 at 17:02
  • 4
    @SteveBarnes: It's constexpr stuff - I'm just looking for a bunch of .hpp files; why would any of those details matter?
    – einpoklum
    Commented Feb 20, 2016 at 17:03
  • It matters because, for example, any assembly "shortcuts" will be cpu specific. Commented Feb 20, 2016 at 17:06
  • 1
    @SteveBarnes: #ifdef CAN_TAKE_SHORTCUT shortcut_code; #else regular_code; #endif ... anyway, removed the text about assembly tricks.
    – einpoklum
    Commented Feb 20, 2016 at 17:26

3 Answers 3



"C++11/14 constexpr based Containers, Algorithms, Random numbers, Parsing, Ray tracing, Synthesizer, and others."

by Bolero Murakami (I think that's the name)

Websites: Main site | GitHub Repo.

  • C++11
  • No releases, use the master branch
  • Updated rarely
  • Boost Software License


  • I haven't tried it.
  • If it's C++11-based, there may be performance issues (w.r.t. compilation time)
  • Seems a bit like overkill for just constexpr math

GCEM - Generalized constexpr Math

by Keith O'Hara

Websites: Main site | GitHub Repo.

  • C++11
  • Template-oriented
  • Last release: 1.12.0, May 2019
  • Updated occasionally

Additional features of interest, from the library's website:

  • Continued fraction expansions and series expansions are implemented using recursive templates.
  • The gcem:: syntax is identical to the C++ standard library (std::).
  • Tested and accurate to floating-point precision against the C++ standard library.
  • Released under a permissive (non-GPL) license.


  • I haven't tried it.
  • If it's C++11-based, there may be performance issues (w.r.t. compilation time)

If you are using gcc to compile your C++ 11 then there is the GCC python plugin which you may be able to do what you need with.

The python gcc plugin allows you to use the full power of python as a part of your gcc compile & build process. Given that python provides full maths libraries, basic by default and very advanced from numpy, and this plugin lets you access gcc internals you should be able to perform almost any compile time calculations that you can imagine.

  • 1
    That's not what I asked for. I don't want to "use the power of python", I want to be able to use some more expressive math for compile-time computations.
    – einpoklum
    Commented Feb 20, 2016 at 19:03
  • python provides expressive and comprehensive calculations. Commented Feb 20, 2016 at 19:16
  • 1
    I'm sure it does, it's just not what I'm looking for. It won't allow help me instantiate an std::array at a length being the square root of something.
    – einpoklum
    Commented Feb 20, 2016 at 19:20
  • @einpoklum - it might be worth adding that and a couple more examples plus which compiler you are using, etc., to your question to try to get it reopened as that is the sort of question details that are being looked for. Commented Feb 21, 2016 at 8:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.