V
Vinny
I have a few floating point questions/issues I wish to ask. An answer or
discussion would be nice too Any links discussion the subject would be
nice too..
1. How do I generate an underflow exception for testing purposes?
2. What is the fastest wat to suppress floating point exceptions?
Take the following situation as example.
float x = 1.0e38, //max float value
y = 1.0e-45, //min float value
z = 0.0f; //useless assignment
z = x / y; // this should generate a overflow exception
I could use exception handling like so:
float x = 1.0e38, //max float value
y = 1.0e-45, //min float value
z = 0.0f; //useless assignment
try {
z = x / y; // this should generate a overflow exception
}
catch( EOverflow &eo ) {
//do anything
z = 1.0e38;
}
catch( EZeroDivide &ez ) {
//do anything
z = 1.0e38;
}
catch( EUnderflow &eu ) {
//do anything
z = 0.0;
}
Or is there a better method?
3. This one is weird and may be my compiler itself. When i use the next
example (same as the first one) and compile it for debugging or release i
sometimes get an exception and sometimes i don't. If it didn't and i was
in debug mode, I notice the value of z was unchanged. No matter what the
"useless assignment"'s value was.
float x = 1.0e38, //max float value
y = 1.0e-45, //min float value
z = 0.0f; //useless assignment
z = x / y; // this should generate a overflow
Thanks in advance..
Greetz,
Vinny
discussion would be nice too Any links discussion the subject would be
nice too..
1. How do I generate an underflow exception for testing purposes?
2. What is the fastest wat to suppress floating point exceptions?
Take the following situation as example.
float x = 1.0e38, //max float value
y = 1.0e-45, //min float value
z = 0.0f; //useless assignment
z = x / y; // this should generate a overflow exception
I could use exception handling like so:
float x = 1.0e38, //max float value
y = 1.0e-45, //min float value
z = 0.0f; //useless assignment
try {
z = x / y; // this should generate a overflow exception
}
catch( EOverflow &eo ) {
//do anything
z = 1.0e38;
}
catch( EZeroDivide &ez ) {
//do anything
z = 1.0e38;
}
catch( EUnderflow &eu ) {
//do anything
z = 0.0;
}
Or is there a better method?
3. This one is weird and may be my compiler itself. When i use the next
example (same as the first one) and compile it for debugging or release i
sometimes get an exception and sometimes i don't. If it didn't and i was
in debug mode, I notice the value of z was unchanged. No matter what the
"useless assignment"'s value was.
float x = 1.0e38, //max float value
y = 1.0e-45, //min float value
z = 0.0f; //useless assignment
z = x / y; // this should generate a overflow
Thanks in advance..
Greetz,
Vinny