Oh oh. Just noticed a Javadoc error in math

I just noticed this(strangely enough) that ceil and floor documentation is in reverse.
Ceil goes towards positive infinity while floor goes towards negative infinity.
When my mouse cursor was highlighted over the word in Eclipse I noticed the docs are wrong and in fact are in reverse when I looked up floor.

How can this bug have gone on for so long? :o

No, it’s correct.

[quote]Returns the largest (closest to positive infinity) double value that is less than or equal to the argument and is equal to a mathematical integer.
Special cases:

  • If the argument value is already equal to a mathematical integer, then the result is the same as the argument.
  • If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument.
    [/quote]
    It returns the number that is closest to positive infinity out of all values that are less than or equal to the argument.

ceil(0.8 ) = 1
floor(0.8 ) = 0

The JavaDocs are saying something different or their wording confused me.

The javadocs are correct, and the methods work the way you describe.

For math.floor:
“Returns the largest (closest to positive infinity) double value that is less than or equal to the argument and is equal to a mathematical integer.”

So, if we take 0.8 as an example, we first find all values that are “less than or equal to the argument and is equal to a mathematical integer.”
We end up with [[…], -4, -3, -2, -1, 0]

Then we find “the largest (closest to positive infinity) double value” out of that list.
That’s 0.

So Math.floor(0.8) returns 0, as that’s the highest number out of all integers less than or equal to the input value.

i think the word “largest” at the start of the sentance confused you.

You need to parse the whole sentance.

Ahh thanks for the explanation.
Now it makes sense.

I was thinking what in the heck was going on.