TransWikia.com

C++ constexpr math (header-only) library

Software Recommendations Asked by einpoklum on February 18, 2021

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.

3 Answers

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

Answered by einpoklum on February 18, 2021

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)

Answered by einpoklum on February 18, 2021

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.

Answered by Steve Barnes on February 18, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP