1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Sep 2012
Posts
2
Rep Power
0

#### Whole number check

Is there an easy way to check if the result of a calculation (bv 10 / 9 or 10 / 5) is a whole number or not?
2. Code:
```if (fmod((double)numerator,(double)denominator))
fputs("NOT ",stdout);
puts("whole");```
3. No Profile Picture
bdb
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Aug 2012
Posts
156
Rep Power
34
Originally Posted by KevinFCTwente
Is there an easy way to check if the result of a calculation (bv 10 / 9 or 10 / 5) is a whole number or not?
The result of integer division (as in your exemple) (except division by zero) is ALWAYS an integer.
The result of floating-point division (except division by zero and overflows) is always a floating-point number.

If you want to determine if a floating point number has the same value as a whole number, that's another problem:
for instance 4.2E-289 is not a whole number (zero?) but 4.2E289 is a whole number.
4. In simple math...

if (numerator == (numerator/denominator)*denominator) then the result of numerator/denominator is a whole number ;
else it isn't ;