[dmd-internals] float.infinity->int test case in constfold.d
David Nadlinger
code at klickverbot.at
Wed Sep 19 10:37:33 PDT 2012
runnable/constfold.d contains the following test case:
---
void test2()
{
float f = float.infinity;
int i = cast(int) f;
writeln(i);
writeln(cast(int)float.max);
assert(i == cast(int)float.max);
assert(i == 0x80000000);
}
---
Is it really valid, i.e. is the result of the cast really defined?
I didn't look up the correct behavior in the C standard, but
interestingly both GCC and Clang (i.e. the LLVM constant folder)
produce int.min in unoptimized builds but int.max in optimized builds
of the following program:
---
#include <iostream>
#include <limits>
int main(int argc, char const *argv[])
{
std::cout <<
static_cast<int>(std::numeric_limits<float>::infinity()) << std::endl;
return 0;
}
---
Can somebody shed light on the issue?
David
More information about the dmd-internals
mailing list