I would like to get the integer and the fractional part of a float. This is easy with std::modf
but the function is not constexpr. What is the reason for this and what is the alternative?
Asked
Active
Viewed 224 times
3

CvR_XX
- 89
- 1
- 1
- 10
-
Does this answer your question? [Why compile-time floating point calculations might not have the same results as run-time calculations?](https://stackoverflow.com/questions/50959021/why-compile-time-floating-point-calculations-might-not-have-the-same-results-as) – super Nov 23 '20 at 10:09
-
Does this answer your question? [Constexpr Math Functions](https://stackoverflow.com/questions/17347935/constexpr-math-functions) – Aykhan Hagverdili Nov 23 '20 at 10:42
-
[Compile-time (constexpr) float modulo?](https://stackoverflow.com/q/14294659/10147399) – Aykhan Hagverdili Nov 23 '20 at 10:44
1 Answers
2
Is there a constexpr alternative to modf
There is no standard constexpr alternative to modf or related math functions.
but the function is not constexpr. What is the reason for this
Those functions pre-exist constexpr. They even pre-exist C++. As such, when those founctions were specified, they couldn't have been constexpr.
There are no standard constexpr alternatives because such proposal hasn't been accepted into the standard. Such change has been proposed, so this may potentially change in a future standard: P1383
what is the alternative?
Wait for the potential future standard, or do the math without using standard functions.

eerorika
- 232,697
- 12
- 197
- 326