Answer the question
In order to leave comments, you need to log in
How to check the parity of a floating point number?
Hello, how to check the parity of a floating point number in C language?
x%2==0 - doesn't work.
Answer the question
In order to leave comments, you need to log in
um
, and if you multiply up to an integer
and x%2==0
, will it work?)
PYSY
can be done like this
var myvar = 124124,2541;
var strmyvar = myvar as string;
var in = strmyvar[strmyvar.Count-1];
bool result = in%2==0;
A real number cannot be even or odd. A real number is always an approximate value (at least for this reason, its remainder when divided by 2 will always be non-zero).
It follows from the context that we are talking about integers represented in real format. If so, then converting to an integer, as advised above, is not a universal method, since the number can go beyond the bit grid of the integer type. You need to check as follows:
0.5*x==round(0.5*x)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question