Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!