DIV/0
Is this enough to check for a divide by zero?
1 2 3 4 5
|
double div(double numerator, double denominator)
{
if (denominator == 0.) return -1.;
return numerator / denominator;
}
|
I've used that in the past and it seems to be good enough.
It could still result in an infinite value.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
#include <iostream>
#include <limits>
double div(double numerator, double denominator)
{
if (denominator == 0.) return -1.;
return numerator / denominator;
}
int main()
{
double a = 1;
double b = std::numeric_limits<double>::denorm_min();
std::cout << div(a, b) << std::endl;
return 0;
}
|
inf |
Thanks.
Topic archived. No new replies allowed.