10
blindXfish
168d

Floor(-9.4)

Comments
  • 4
    Well, it's not wrong 😂

    It's not what you would expect first look, but it's actually right.
  • 2
    This annoys me more than it should
  • 6
    Most buildings here only go down to -2
  • 1
    So where is the actual rant?
  • 1
    weren't you expecting -10?
    That's how math works, Greatest Integer lower than or equal to -9.4
  • 0
    I expected floor to be 0 not - infinity
  • 0
    @blindXfish In which mathematics does floor of -9.4 gives 0?

    It doesn't give infinity in JS, which language are you using?
  • 0
    @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.
  • 3
    @blindXfish If you go by the definition "Greatest Integer lower than or equal to something" It will make sense.
  • 4
    @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
  • 1
    @theabbie It does. Kind of disappointing.
  • 0
    @blindXfish Depends on the usecase, Rules don't break for negative integers, Maybe you're looking to round off it.
  • 3
    @theabbie Do you...

    - round toward zero?
    - round away from zero?
    - round toward negative infinity?
    - round toward positive infinity?

    ;)
  • 1
    @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
  • 0
    @theabbie It depends; libraries like MPFR give you a choice because the behavior of rounding can be specified differently in different scenarios.
  • 0
    @junon As per definition, "Nearest Integer", it's well-defined.
  • 3
    @theabbie so much rage and frustration in floor(). I typed basically one word. :D
  • 0
    @blindXfish Your rant is irrelevant now, it's about mathematics now
  • 1
    @blindXfish we’ve entered the realm of hundred comment theological debate posts
  • 1
    @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).
  • 2
    @junon Mathematical rules don't change, they can't change.
  • 2
    @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.
  • 1
    @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.
  • 0
    @junon
    Do you know any programming language, wich implements floor different from mathematics?
  • 1
    @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.
  • 2
    @theabbie I think you mean mathematical axioms. Mathematical rules can be disputed, extended or limitted to different domains.
  • 1
    @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.
  • 1
    @theabbie What is 18446744073709551615 + 1 in C?
  • 0
    @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"?
  • 0
    @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.
  • 2
    @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! 😃
  • 1
    JavaScript to the rescue! (lol)

    ~~(-9.4) returns -9
    ~~(9.4) returns 9

    It's a hack but it works
Add Comment