In article <(E-Mail Removed) .com> "William Hughes" <(E-Mail Removed)> writes:

....

> I am not sure what you are requiring of a sane implementation.

>

> But it seems to me that even on a sane implementation we could

> have

> x compares less than 1.5

> x + 0.5 compares equal to 2
I think not. Consider 1.5, in binary that would be 1.1, and any number

larger than 1 and smaller than 1.5 would (in binary) start with 1.0.

Adding 0.5 to that would merely replace that 0 by an 1, and such a number

should not compare equal to 2. At least on a sane implementation. (I

have worked with only one system where two numbers could compare equal

while they actually were not equal, I tend to call such a system insane.)

> How about assuming that

> -if y is an integer, y+0.5 is exaclty representable and

> the expression y+0.5 will produce this representation

> (this could be considered sane behaviour for a system with

> radix 2 assuming y is not too large)
See the latter requirement. If y is too large this can be false.

Especially this is false under IEEE double precision when x is (say)

2^52 + 1. Adding 0.5 to it results in 2^52 + 2 (round to even rule).

> double round(double x)

> {

> if(x < ((floor)(x) + 0.5) )

> {

> return floor(x);

> }
I do not think you want this. Suppose x == 0.75, it will return 0.0.

--

dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131

home: bovenover 215, 1025 jn amsterdam, nederland;

http://www.cwi.nl/~dik/