4

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?

Notes:

  • 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. – Steve Barnes Feb 20 '16 at 17:02
  • 3
    @SteveBarnes: It's constexpr stuff - I'm just looking for a bunch of .hpp files; why would any of those details matter? – einpoklum Feb 20 '16 at 17:03
  • It matters because, for example, any assembly "shortcuts" will be cpu specific. – Steve Barnes Feb 20 '16 at 17:06
  • @SteveBarnes: #ifdef CAN_TAKE_SHORTCUT shortcut_code; #else regular_code; #endif ... anyway, removed the text about assembly tricks. – einpoklum Feb 20 '16 at 17:26
0

Sprout

"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

Caveats:

  • 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
| improve this answer | |
0

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.

Caveat:

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

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.

| improve this answer | |
  • 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 Feb 20 '16 at 19:03
  • python provides expressive and comprehensive calculations. – Steve Barnes Feb 20 '16 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 Feb 20 '16 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. – Steve Barnes Feb 21 '16 at 8:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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