I'm running into an issue with certain double to unsigned __int64 typecasts in C++ Builder 10.1 Berlin throwing a floating point invalid operation exception($C0000090).
My application allows for user input, so I need to be able to handle any values, but for simplicity, let's use the following example:
double dValue = 9223372036854775807.0;
unsigned __int64 uhValue = (unsigned __int64) dValue;
While I can handle this exception in a try/catch, this appears to corrupt the FPU register stack, and subsequent floating point operations will generate a floating point stack check exception.
The following problem report describes a similar issue and has a potential workaround: http://qc.embarcadero.com/wc/qcmain.aspx/qcmain.aspx?d=119745
I'd like to prevent the initial floating point exception if at all possible. Precision loss aside, the value stored in the double is within the valid unsigned __int64 range, so I'm having trouble understanding what's causing the exception.
Is there something I could be doing differently when it comes to the typecast/conversion or exception handling?
As a side note, the code snippet above runs fine in Visual Studio and sets uhValue to 9223372036854775808.
Thank you!