Closed GWRon closed 4 years ago
Floating point numbers never cause division-by-zero errors; that's by design and not specific to BlitzMax.
https://en.cppreference.com/w/cpp/numeric/math/fmod
Error handling Errors are reported as specified in math_errhandling.
Domain error may occur if y is zero.
If the implementation supports IEEE floating-point arithmetic (IEC 60559),
If x is ±0 and y is not zero, ±0 is returned If x is ±∞ and y is not NaN, NaN is returned and FE_INVALID is raised If y is ±0 and x is not NaN, NaN is returned and FE_INVALID is raised If y is ±∞ and x is finite, x is returned. If either argument is NaN, NaN is returned
what is this "domain error" ?
https://en.cppreference.com/w/cpp/error/domain_error
so ... isn't it throwing an exception then?
On the same page you linked (https://en.cppreference.com/w/cpp/numeric/math/fmod):
If a domain error occurs, an implementation-defined value is returned (NaN where supported)
so ... isn't it throwing an exception then?
No. Integer division by zero doesn't throw an exception either, at least in the BlitzMax sense of the term. It's an error on the same level as a stack overflow or a segfault and terminates your program. Technically there are ways to catch even these, but that's not really a rabbit hole we wanna go down, I think...
OK
I already mentioned it in the issue https://github.com/bmx-ng/bcc/issues/527 but maybe it got a bit lost there ...
The illegal instruction bug is fixed now, but the following code does not result in a "division by zero error":
It just outputs:
I am not absolutely sure (dunno what "fmod" outputs - and gives for errors) but I would have thought it leads to a "division by zero" too.
I might be no "big issue" - but assume
mod 0
ismod X
... and someone wants to print everytime the remainder is not 0 ...In both cases this is printed ... - yes, the code is "by intention" exotic and most probably nowhere used. If the first number was a "integer", BCC would catch it with a "division by zero" - but for
double
it might lead to "unexpected" behaviour - maybe leading to a bug (the "mod 0") not being spotted by the developer.But as said ... dunno how "fmod" (or other languages than C) handle it.