P
Paul Lutus
Mark Thornton wrote:
/ ...
Please? To what does this refer? I offered two alternatives.
This is true if you limit the values to doubles containing integers of less
than 16 decimal places. My point was the case where someone tries to test a
double value that is not an integer, dubious as this sounds from a
mathematical standpoint.
All true for doubles that are integers, assuming they fall in the
16-decimal-digit limit for doubles.
Yes, again, assuming the values are integers. My point was someone might
want to test a double that is not an integer, to discover whether the
integer component was odd or even.
After posting I ran some tests and established this. But it leaves open the
possibility that someone might apply a double that is not an integer. I am
not justifying it, only considering it.
/ ...
Yes it is.
Please? To what does this refer? I offered two alternatives.
Ignoring the special values, the remainder a%b is always a
member of the set of values exactly representable by a double (assuming
a and b are double values). That is the remainder does not have to be
rounded or truncated to a nearby value.
This is true if you limit the values to doubles containing integers of less
than 16 decimal places. My point was the case where someone tries to test a
double value that is not an integer, dubious as this sounds from a
mathematical standpoint.
Thus a%2 will be zero if and only if 'a' an even integer. Similarly
Math.abs(a)%2 will be 1 if and only if 'a' is an odd integer.
All true for doubles that are integers, assuming they fall in the
16-decimal-digit limit for doubles.
Note I could rewrite the tests as
a%2 == 0.0
and
Math.abs(a)%2 == 1.0
Yes, again, assuming the values are integers. My point was someone might
want to test a double that is not an integer, to discover whether the
integer component was odd or even.
this makes it clear that the comparison is done on double values.
After posting I ran some tests and established this. But it leaves open the
possibility that someone might apply a double that is not an integer. I am
not justifying it, only considering it.