[cp-patches] FYI: Point.setLocation() fix

David Gilbert 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> 
>>>>>>> writes:
>>>>>>>           
>>>>>>
>>
>> David> +    this.x = (int) Math.floor(x + 0.5);
>> David> +    this.y = (int) Math.floor(y + 0.5);
>>
>> Math.round()?
>> Or maybe Math.rint()?
>>
>> Tom
>>
>>  
>>
> 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...
>
> Regards,
>
> Dave
>
Math.rint() fails for some regular test cases, for example:

    p.setLocation(1.5, 2.5);
    harness.check(p.x, 2);
    harness.check(p.y, 3);   

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...

Regards,

Dave

(*)  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 mailing list