Ranter
Join devRant
Do all the things like
++ or  rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power realtime personalized recommendations and activity feeds using a simple API
Learn More
Comments

C0D46254661dWell, it's not wrong ðŸ˜‚
It's not what you would expect first look, but it's actually right. 
theabbie392661dweren't you expecting 10?
That's how math works, Greatest Integer lower than or equal to 9.4 
theabbie392661d@blindXfish In which mathematics does floor of 9.4 gives 0?
It doesn't give infinity in JS, which language are you using? 
blindXfish50261d@theabbie I didn't said floor of  9.4, I said floor in general concept of the meaning. In my reality, at least until now, floor (in general concept) had a meaning of getting closer to 0 instead of getting closer to minus infinity.

theabbie392661d@blindXfish If you go by the definition "Greatest Integer lower than or equal to something" It will make sense.

C0D46254661d@theabbie any C based language would give 10
@blindXfish you may want to look at a number line.
Floor() rounds to next "lowest" whole number.
When your in negative digits, you have to continue going down "10" not up, which would be CEIL(), to 0 
theabbie392661d@blindXfish Depends on the usecase, Rules don't break for negative integers, Maybe you're looking to round off it.

junon294461d@theabbie Do you...
 round toward zero?
 round away from zero?
 round toward negative infinity?
 round toward positive infinity?
;) 
theabbie392661d@junon Round off is independent of sign, If fractional part is less than 0.5, Remove the Fractional part, if greater than 0.5, Increment the absolute value and preserve the sign,
round(9.4) = 9
round(9.6) = 10 
junon294461d@theabbie It depends; libraries like MPFR give you a choice because the behavior of rounding can be specified differently in different scenarios.

blindXfish50261d@theabbie so much rage and frustration in floor(). I typed basically one word. :D

junon294461d@theabbie Again, which definition? There is the mathematical definition, but that does not always apply in the CS realm.
"Floor" can mean "truncation", which works very differently than your definition (e.g. it rounds toward zero). 
junon294461d@theabbie Yes, but the application of `floor()` in computer science obviously has conflicting definitions.
Not all symbols and functions are equal across mathematics/scientific disciplines. This is also why mathematic symbols change their meanings depending on the domain. 
theabbie392661d@junon If you are using floor to parse integers, that's a bad practice, having different applications doesn't mean mathematical rules changed, floor Function is still doing the mathematical floor.

Oktokolo175361d@junon
Do you know any programming language, wich implements floor different from mathematics? 
junon294461d@Oktokolo Do you know what MPFR is?
Also did anyone actually read my comment? I never even said floor to begin with. Just that floor is sometimes implemented as truncate. 
bioDan561561d@theabbie I think you mean mathematical axioms. Mathematical rules can be disputed, extended or limitted to different domains.

theabbie392660d@bioDan I meant mathematical definitions, Floor is defined as "Greatest integer lower than or equal to" this is a completely unambiguous definition, this definition doesn't change anywhere, in whatever Programming language this function is implemented.

Oktokolo175360d@junon
MPFR implements mpfr_floor like defined by mathematics (returns nearest integer less than or equal to given value).
So do you actually know of any example for "the application of `floor()` in computer science obviously has conflicting definitions"? 
theabbie392660d@junon That is a way of storing it, It's because of memory limitations, even if it wraps up that does not mean huge_number + 1 is equal to the wrapped up negative number. If computers had unlimited memory, these problems wouldn't exist.

bioDan561560d@theabbie oh i dont dispute that definition of floor at all, just commenting on the use of the term "mathematical rules". Definition seems more correct. Ship it! ðŸ˜ƒ

rooter154360dTbh, i should have known this i guess.
Some python results.
```
>>> math.floor(9.4)
10
>>> math.floor(9.6)
10
>>> round(9.4)
9
>>> round(9.6)
10
>>> math.floor(9.4)
9
>>> math.floor(9.6)
9
```
Well, this is why we write (weird) tests 
ThermalCube23160dJavaScript to the rescue! (lol)
~~(9.4) returns 9
~~(9.4) returns 9
It's a hack but it works
Floor(9.4)
rant