I have a program in C++ where I divide two numbers, and I need to know if the answer is an integer or not. What I am using is:
if(fmod(answer,1) == 0)
I also tried this:
if(floor(answer)==answer)
The problem is that answer usually is a 5 digit number, but with many decimals. For example, answer can be: 58696.000000000000000025658 and the program considers that an integer.
Is there any way I can make this work?
I am dividing double a/double b= double answer
(sometimes there are more than 30 decimals)
Thanks!
EDIT: a and b are numbers in the thousands (about 100,000) which are then raised to powers of 2 and 3, added together and divided (according to a complicated formula). So I am plugging in various a and b values and looking at the answer. I will only keep the a and b values that make the answer an integer. An example of what I got for one of the answers was: 218624 which my program above considered to be an integer, but it really was: 218624.00000000000000000056982 So I need a code that can distinguish integers with more than 20-30 decimals.
aandbin youra/bexample come from?double. You'd need to use a high precision floating point library.doublein the format most C++ implementations use. Did you obtain this result indouble(implying your implementation uses a very long format fordouble), obtain it inlong doubleor another built-in type in a C++ program (possibly a type that is an extension in your implementation), obtain it with other software, or obtain it by other mathematics (e.g., pen and paper)? Is it an example of a number that should be treated as an integer because the fractional part is only the result of floating-point approximations or…