Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Math.floor( )

 
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok , here's what the floor() for Math class say's
floor
public static double floor(double a)
Returns the largest (closest to positive infinity) double value that is not greater than the argument and is equal to a mathematical integer.
Parameters:
a - a double value.
a - an assigned value.
Returns:
the largest (closest to positive infinity) double value that is not greater than the argument and is equal to a mathematical integer.
With the above in mind i expected
Math.floor(-5.2) = -5; //incorrect
instead
Math.floor(-5.2) = -6; //correct
Can somebody explain as to why cause with this i figure that the statement " not greater than the argument and is equal to a mathematical integer " is either wrong ( LOL ) or i just don't seem to get the language .
BTW the question bears root's in the 3rd & last post on this thread http://www.javaranch.com/ubb/Forum24/HTML/011243.html
Thanx
Ashish
[This message has been edited by Ashish Hareet (edited July 30, 2001).]
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think u explained about math.round() in the thread u mentioned .
But in the above case it is math.floor().
so,
Math.floor(5.2)=5.0
Same way
Math.floor(-5.2)=-6.0
as it is negative number now.
Which explains"not greater than the argument(-5.2) and is equal to a mathematical integer "
HTH.
Thanx
Rajani
 
Ashish Hareet
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rajani ,
Silly me , i thought
-6 > -5.2 . Insomnia i guess
Thanx
Ashish
[This message has been edited by Ashish Hareet (edited July 30, 2001).]
 
Mini Pilla
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ashish,
Don't make u'r brain to try so hard for SCJP.
HAve to b cool for the exam!!!
But even I do such mistakes!!
-
Rajani

[This message has been edited by Rajani Katta (edited July 30, 2001).]
 
Ashish Hareet
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx Rajani , the whole darn thing get's too much sometimes .
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ashish! Here's a clear and simple definition for the floor and ceiling method. For floor, it the next lower number and for ceiling, it's the next higher number. -6 is the right answer. If ceiling was used, the answer would have been -5. -6 is less(lower) than -5.2 and -5 is greater(higher) than -5.2. Good luck Ashish.
Saki

Originally posted by Ashish Hareet:
Ok , here's what the floor() for Math class say's
floor
public static double floor(double a)
Returns the largest (closest to positive infinity) double value that is not greater than the argument and is equal to a mathematical integer.
Parameters:
a - a double value.
a - an assigned value.
Returns:
the largest (closest to positive infinity) double value that is not greater than the argument and is equal to a mathematical integer.
With the above in mind i expected
Math.floor(-5.2) = -5; //incorrect
instead
Math.floor(-5.2) = -6; //correct
Can somebody explain as to why cause with this i figure that the statement " not greater than the argument and is equal to a mathematical integer " is either wrong ( LOL ) or i just don't seem to get the language .
BTW the question bears root's in the 3rd & last post on this thread http://www.javaranch.com/ubb/Forum24/HTML/011243.html
Thanx
Ashish
[This message has been edited by Ashish Hareet (edited July 30, 2001).]


 
Ashish Hareet
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx Saki
 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I follow an easy way to remember floor & ceil.
I assume I am the number standing in a room.
floor() means the floor under me. Always lower;
In other words, The floor() returned number should be lesser than me.
ceil() means the ceiling above me. Always higher than me.
In other words, The ceil() returned number should be greater than me.
It had always worked correctly.
Any comments...
tvs sundaram
 
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It will be helpful if we look at the problem using the
following approach:

Hope it helps.
Guoqiao
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic