You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by Vincent Hennebert <vi...@anyware-tech.com> on 2008/02/11 11:23:21 UTC

Re: svn commit: r620277 - /xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/NumberProperty.java

Hi Andreas,

> Author: adelmelle
> Date: Sun Feb 10 05:01:07 2008
> New Revision: 620277
<snip/>
> +    private NumberProperty(double num) {
> +        //Store the number as an int or a long,
> +        //if possible
> +        if ((num >= 0 && num == Math.floor(num))
> +                || num == Math.ceil(num)) {

Isn’t that the same as
    if (num == Math.floor(num))
? Or replace floor with ceil or rint, basically if the number actually 
is an integer, then the 3 methods should return a value equal to num 
itself.

Unless I missed something?

Vincent


-- 
Vincent Hennebert                            Anyware Technologies
http://people.apache.org/~vhennebert         http://www.anyware-tech.com
Apache FOP Committer                         FOP Development/Consulting

Re: svn commit: r620277 - /xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/NumberProperty.java

Posted by Andreas Delmelle <an...@telenet.be>.
On Feb 11, 2008, at 19:26, Andreas Delmelle wrote:

<snip />
> So,
>
> Math.floor(-2.3) = -3
> Math.ceil(-2.3) = -2
> Math.rint(-2.3) = -2
>
> rint() has the additional side-effect of returning just the closest  
> even integer, so:
>
> Math.rint(-3.3) == Math.floor(-3.3) != Math.ceil(-3.3)

Correction, this would only holds for -3.5 because that is a value  
that is as close to -4 as it is to -3.


Re: svn commit: r620277 - /xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/NumberProperty.java

Posted by Andreas Delmelle <an...@telenet.be>.
On Feb 11, 2008, at 19:26, Andreas Delmelle wrote:

>>
>> Err...
>> Math.floor(-2.0) == Math.ceil(-2.0) == Math.rint(-2.0) == -2.0
>
> Did you actually check that? In that case, your JVM would not be  
> compliant, I think...
>
> The API docs say:
>
> Math.floor(-2.3) = -3
> Math.ceil(-2.3) = -2
> Math.rint(-2.3) = -2

Sorry, must be the Monday...
Of course, we're both absolutely right, and for doubles that  
correspond to integers, what I wrote actually does not matter...


Cheers

Andreas

Re: svn commit: r620277 - /xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/NumberProperty.java

Posted by Andreas Delmelle <an...@telenet.be>.
On Feb 11, 2008, at 18:05, Vincent Hennebert wrote:

Hi

> Andreas Delmelle wrote:
>> On Feb 11, 2008, at 11:23, Vincent Hennebert wrote:
>>
>>>> +        if ((num >= 0 && num == Math.floor(num))
>>>> +                || num == Math.ceil(num)) {
>>>
>>> Isn’t that the same as
>>>     if (num == Math.floor(num))
>>
>> Yes, for positive integers. For negative ints, it is 'num ==
>> Math.ceil(num)'.
>
> Err...
> Math.floor(-2.0) == Math.ceil(-2.0) == Math.rint(-2.0) == -2.0

Did you actually check that? In that case, your JVM would not be  
compliant, I think...

The API docs say:

floor() -> the largest (closest to positive infinity) double value  
that is not greater than the argument and is equal to a mathematical  
integer
ceil() -> the smallest (closest to negative infinity) double value  
that is not less than the argument and is equal to a mathematical  
integer
rint() -> the double value that is closest in value to the argument  
and is equal to a mathematical integer.


So,

Math.floor(-2.3) = -3
Math.ceil(-2.3) = -2
Math.rint(-2.3) = -2

rint() has the additional side-effect of returning just the closest  
even integer, so:

Math.rint(-3.3) == Math.floor(-3.3) != Math.ceil(-3.3)

As for my proposed alternative, that should obviously be:

Math.abs(num) == Math.floor(Math.abs(num))

Cheers

Andreas

Re: svn commit: r620277 - /xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/NumberProperty.java

Posted by Vincent Hennebert <vi...@anyware-tech.com>.
Andreas Delmelle wrote:
> On Feb 11, 2008, at 11:23, Vincent Hennebert wrote:
> 
> Hi Vincent
> 
>> Hi Andreas,
>>
>>> Author: adelmelle
>>> Date: Sun Feb 10 05:01:07 2008
>>> New Revision: 620277
>> <snip/>
>>> +    private NumberProperty(double num) {
>>> +        //Store the number as an int or a long,
>>> +        //if possible
>>> +        if ((num >= 0 && num == Math.floor(num))
>>> +                || num == Math.ceil(num)) {
>>
>> Isn’t that the same as
>>     if (num == Math.floor(num))
> 
> Yes, for positive integers. For negative ints, it is 'num ==
> Math.ceil(num)'.

Err...
Math.floor(-2.0) == Math.ceil(-2.0) == Math.rint(-2.0) == -2.0

And same for a positive double. No need to make the distinction.

Vincent


-- 
Vincent Hennebert                            Anyware Technologies
http://people.apache.org/~vhennebert         http://www.anyware-tech.com
Apache FOP Committer                         FOP Development/Consulting

Re: svn commit: r620277 - /xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/NumberProperty.java

Posted by Andreas Delmelle <an...@telenet.be>.
On Feb 11, 2008, at 11:23, Vincent Hennebert wrote:

Hi Vincent

> Hi Andreas,
>
>> Author: adelmelle
>> Date: Sun Feb 10 05:01:07 2008
>> New Revision: 620277
> <snip/>
>> +    private NumberProperty(double num) {
>> +        //Store the number as an int or a long,
>> +        //if possible
>> +        if ((num >= 0 && num == Math.floor(num))
>> +                || num == Math.ceil(num)) {
>
> Isn’t that the same as
>     if (num == Math.floor(num))

Yes, for positive integers. For negative ints, it is 'num == Math.ceil 
(num)'.

Alternative would be: Math.abs(num) == Math.floor(num)

Cheers

Andreas