Topic: constexpr and math functions
Author: restor <akrzemi1@interia.pl>
Date: Fri, 10 Aug 2007 07:16:59 CST Raw View
Now that C++0x provides tools for compile-time computations could it
also add math functions evaluated at compile-time to the standard
library? One of the examples in N2116 shows the usage of complex
numbers:
constexpr complex I(0, 1);
constexpr double xx = I.real();
It would be useful if we could also define complex class literals with
polar coordinates:
constexpr complex = complex::polar( 0.5 * PI, 1 );
constexpr double xx = I.real();
In order to do that we would have to have a constexpr sin function.
making std::sin a constexpr is probably unrealistic, but providing a
set of math constexpr functions seams fair. Sine can be represented as
a set of additions and multiplications that meet constexpr
requirements.
Such a std::compiletime::sin might also be useful in run-time. It
would give a guarantee of a deterministic function (at the expense of
performance).
&rzej
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]