Loading ...
Sorry, an error occurred while loading the content.

Re: [jslint] Re: JSLint rejects (n % 1)

Expand Messages
  • mathew
    ... Yes. The meaning of n - Math.floor(n) is obvious. The meaning of n % 1 is not obvious, so much so that at least one person on this mailing list
    Message 1 of 9 , Apr 28 7:12 AM
    View Source
    • 0 Attachment
      On Thu, Apr 28, 2011 at 07:46, Martin <mbrrtt@...> wrote:

      > Do you really think that 'n % 1' is 'clever code', while 'n -
      > Math.floor(n)' is not?
      >

      Yes. The meaning of 'n - Math.floor(n)' is obvious. The meaning of 'n % 1'
      is not obvious, so much so that at least one person on this mailing list
      misunderstood it.

      > Sure, the operator '%' doesn't wear its meaning on its face. It's not
      > standard mathematical notation; you have to look it up the first time you
      > see it, in a book or in the spec. But did you know what 'x || y' or 'x ? y :
      > z' meant the first time you saw them?
      >
      The problem isn't the meaning of '%'; I knew that % was remainder/modulo.
      The problem is that extending modulo to floating point gives you at least
      three different possible behaviors, as
      http://en.wikipedia.org/wiki/Modulo_operation points out, and people's
      expectations aren't necessarily met by those extended definitions.


      mathew
      --
      <URL:http://www.pobox.com/~meta/>


      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.