Jeremie Pelletier wrote:
Is there a way to convert a float (or double/real) to an integral number
without changing its binary representation at compile time?
I need to extract the sign, exponent and mantissa yet I cant use bit shifting.
"Error: 'R' is not of integral type, it is a real" is the error I get.
The usual *cast(uint*)&value wont work either at compile time.
Any suggestions?
I got this to work, would it be applicable to your need?
void main(string[] args)
{
union A
{
double x;
int y;
}
enum A a = A(0.3);
writeln(a.x);
writeln(a.y);
}
Andrei