Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Can I trap (and recover from) floating point overflow errors?

0
10 Posted

Can I trap (and recover from) floating point overflow errors?

0

Duncan Murdoch [dm] writes: Because the floating point processor operates in parallel to the integer processor, this is generally quite tricky. The best approach is not to trap the errors, but just to mask them, and at the end of a calculation check whether they have occurred by examining the coprocessor status word. Be aware that Borland’s string-conversion routines (used in Str, Write and Writeln) clear the FPU’s status word. If you do any I/O of floating point values in between status checks, you may miss seeing signs of errors. I would add that it’s probably best to leave the floating point overflow exception on (unmasked) in the vast majority of your code, and that you should only mask it off around the few calculations where you expect and can handle a possible overflow. That is, a runtime error is probably better than allowing the program to continue with unnoticed math errors!

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.