• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Math.floor() question

 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does anyone know why Math.floor(-100.6) results in -101.0?
I thought floor was suppose to return the largest double value that is not greater than the arguement.
-100 is larger than -101. So why doesnt't it return -100.
Is the method floor actually calculating on the absolute value of the value passed. Like:
Math.floor(-100.6)
1. takes -100.6 and computes on 100.6.
2. 101.1 = 100.6 +.5
3. returns the long of 101.1 which is 101
4 the final result would then be -101.00
 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It cannot return -100, because -100 is GREATER than -100.6. So the closest value is -101. The closer a negative number is to zero, the larger it is.
Hope this helps.
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You had provided the answer to your question within your question itself.



I thought floor was suppose to return the largest double value that is not greater than the arguement.

 
Charlie Swanson
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I understand Thanks.
 
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Charlie,
It helps to physically visualize a room "ceiling" and "floor".
Floor is at your feet and the ceiling is above your head.
<*****> Ceil
XXX
<-----> Floor
For positive number, it's easy. You just put your number where the XXX is and bracket it with the top and bottom non-decimal number.
E.g. 10.2
<*****> Ceil = 11.0
10.2
<-----> Floor = 10.0
For negative numbers, it gets a little tricky. You just have to remember that a smaller negative number is actually larger than a big negative number. So you do the reverse.
E.g. -100.6
<*****> Ceil = -100.0
-100.6
<-----> Floor = -101.0
There are a couple of special cases you'll have to memorize, but they aren't too difficult. Look at the API.
-Peter
reply
    Bookmark Topic Watch Topic
  • New Topic