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 real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
C0D4681384yWell, it's not wrong 😂
It's not what you would expect first look, but it's actually right. -
weren't you expecting -10?
That's how math works, Greatest Integer lower than or equal to -9.4 -
@blindXfish In which mathematics does floor of -9.4 gives 0?
It doesn't give infinity in JS, which language are you using? -
@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.
-
@blindXfish If you go by the definition "Greatest Integer lower than or equal to something" It will make sense.
-
C0D4681384y@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 -
@blindXfish Depends on the usecase, Rules don't break for negative integers, Maybe you're looking to round off it.
-
@theabbie Do you...
- round toward zero?
- round away from zero?
- round toward negative infinity?
- round toward positive infinity?
;) -
@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 -
@theabbie It depends; libraries like MPFR give you a choice because the behavior of rounding can be specified differently in different scenarios.
-
@theabbie so much rage and frustration in floor(). I typed basically one word. :D
-
@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). -
@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. -
@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.
-
@junon
Do you know any programming language, wich implements floor different from mathematics? -
@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. -
bioDan61594y@theabbie I think you mean mathematical axioms. Mathematical rules can be disputed, extended or limitted to different domains.
-
@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.
-
@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"? -
@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.
-
bioDan61594y@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! 😃
-
JavaScript to the rescue! (lol)
~~(-9.4) returns -9
~~(9.4) returns 9
It's a hack but it works
Floor(-9.4)
rant