• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Flooring VS Ceiling  RSS feed

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can some one please tell me what is the differense between flooring and celing with the help of some examples ???
Thanking you in anticipation.
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bhaskar
You can think of floor and ceil as rounding the arguments. For floor it rounds the argument down (towards negative infinity) to the next whole integer, so these two lines
System.out.println(Math.floor(1.2));
System.out.println(Math.floor(-1.2));
will print
1
-2
Math.ceil rounds the argument up (towards positive infinity), so the lines
System.out.println(Math.ceil(1.2));
System.out.println(Math.ceil(-1.2));
will print
2
-1
It's fairly obvious how to do the positive numbers but the negative numbers are what throw me sometimes. There are some special cases for when the number is NaN or when it is one of the infinities, check out the API for the exact details.
hope this helps
Dave


[This message has been edited by Dave Vick (edited July 05, 2001).]
 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe that the definitions are -
floor: the first integer number not bigger than the given value
e.g. floor(1.2) -> 1
floor(-1.2) -> -2
ceil: the first integer number not less then the given value
e.g. ceil(1.2) -> 2
ceil(-1.2) -> -1
With this in mind, negative number is no problem.
I know this amounts to the same as what Dave said, just thought I'd clarify a bit.
/Mike
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bhaskar,
I prefer using graphics to help me remember:
Ceiling --->
-2 -1 0 +1 +2
Floor <---<br /> Now we can easily see the examples (negative or positive):<br /> floor(1.2) ---> 1.0
floor(-1.2) ---> -2.0
ceil(1.2) ---> 2.0
ceil(-1.2) --> -1.0
A picture is worth a thousand words,
Manfred.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!