[cp-patches] FYI: Point.setLocation() fix
david.gilbert at object-refinery.com
Tue Jun 27 16:21:58 UTC 2006
David Gilbert wrote:
> Tom Tromey wrote:
>>>>>>> "David" == David Gilbert <david.gilbert at object-refinery.com>
>> David> + this.x = (int) Math.floor(x + 0.5);
>> David> + this.y = (int) Math.floor(y + 0.5);
>> Or maybe Math.rint()?
> I thought Math.round(), but the API docs said it was equivalent to
> Math.floor(x + 0.5) and it returns a long, so I thought I might as
> well call Math.floor() directly. Didn't try Math.rint(), but I'll
> take a look...
Math.rint() fails for some regular test cases, for example:
Math.round() fails only for the test cases where the values are outside
the range Integer.MIN_VALUE to Integer.MAX_VALUE (can't say I understand
why, perhaps it is the intermediate cast to 'long' inside Math.round() (*)).
The existing code passes all the Mauve tests I have, so I'll commit
those tests and leave the Point class as is for now...
(*) I know, I should put my thinking cap on and figure it out, but it
is late in the day for me!
More information about the Classpath-patches