Javascript test %4

Discussion in 'Javascript' started by Cogito, Mar 7, 2007.

  1. Cogito

    Cogito Guest

    I'm trying to understand some Javascript code from a certain site.
    Could you please tell me what does this test mean?
    if ( j%4 == 0 )
    What does %4 test for and is there a web site that explains it and,
    presumably, also %1, %2 etc.
     
    Cogito, Mar 7, 2007
    #1
    1. Advertising

  2. Cogito

    Guest

    1. Advertising

  3. Cogito

    Randy Webb Guest

    Cogito said the following on 3/6/2007 11:52 PM:
    > I'm trying to understand some Javascript code from a certain site.
    > Could you please tell me what does this test mean?
    > if ( j%4 == 0 )
    > What does %4 test for and is there a web site that explains it and,
    > presumably, also %1, %2 etc.


    The statement above means if the remainder of dividing j by 4 is 0.
    You can change the 0 to anything smaller than j.

    --
    Randy
    Chance Favors The Prepared Mind
    comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
     
    Randy Webb, Mar 7, 2007
    #3
  4. Cogito

    Cogito Guest

    Such quick replies. It's simply magic.
    Thank you guys.
     
    Cogito, Mar 7, 2007
    #4
  5. Cogito

    Evertjan. Guest

    Randy Webb wrote on 07 mrt 2007 in comp.lang.javascript:

    > Cogito said the following on 3/6/2007 11:52 PM:
    >> I'm trying to understand some Javascript code from a certain site.
    >> Could you please tell me what does this test mean?
    >> if ( j%4 == 0 )
    >> What does %4 test for and is there a web site that explains it and,
    >> presumably, also %1, %2 etc.

    >
    > The statement above means if the remainder of dividing j by 4 is 0.
    > You can change the 0 to anything smaller than j.
    >


    There is no such limitation.

    ;-)

    But to be useful:
    Anything? Also any fraction or any negative integer?

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Mar 7, 2007
    #5
  6. In comp.lang.javascript message <Xns98EC70FE9A9DBeejj99@194.109.133.242>
    , Wed, 7 Mar 2007 10:06:28, Evertjan. <>
    posted:
    >Randy Webb wrote on 07 mrt 2007 in comp.lang.javascript:
    >
    >> Cogito said the following on 3/6/2007 11:52 PM:
    >>> I'm trying to understand some Javascript code from a certain site.
    >>> Could you please tell me what does this test mean?
    >>> if ( j%4 == 0 )
    >>> What does %4 test for and is there a web site that explains it and,
    >>> presumably, also %1, %2 etc.

    >>
    >> The statement above means if the remainder of dividing j by 4 is 0.
    >> You can change the 0 to anything smaller than j.
    >>

    >
    >There is no such limitation.
    >
    >;-)
    >
    >But to be useful:
    >Anything? Also any fraction or any negative integer?


    Yes, yes.

    ISTM that, unless the code is an obfuscation of false, the right hand
    side must be, or have a chance of being, smaller in absolute value than
    the divisor is or may be. And, generally, all three values need to be
    such as can be represented exactly by an IEEE Double, including NaN, if
    the statement is to be reliably usable.

    The OP could easily have answered his question by searching the PDF of
    the Standards (FAQ cites one of them, IIRC) for "%".

    The sections of the standards dealing with the % operator need
    rewriting; at present, they use "floating-point" to mean "non-integer".
    All Numbers are floating point currently.

    It's a good idea to read the newsgroup and its FAQ. See below.

    --
    (c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
    news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
    <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
     
    Dr J R Stockton, Mar 7, 2007
    #6
  7. Cogito

    Randy Webb Guest

    Evertjan. said the following on 3/7/2007 5:06 AM:
    > Randy Webb wrote on 07 mrt 2007 in comp.lang.javascript:
    >
    >> Cogito said the following on 3/6/2007 11:52 PM:
    >>> I'm trying to understand some Javascript code from a certain site.
    >>> Could you please tell me what does this test mean?
    >>> if ( j%4 == 0 )
    >>> What does %4 test for and is there a web site that explains it and,
    >>> presumably, also %1, %2 etc.

    >> The statement above means if the remainder of dividing j by 4 is 0.
    >> You can change the 0 to anything smaller than j.
    >>

    >
    > There is no such limitation.
    >
    > ;-)


    Tis true, but the results are pretty useles if k is smaller than j in j%k.

    > But to be useful:
    > Anything? Also any fraction or any negative integer?


    Yes. Or at least testing doesn't throw up on fractions or negative
    integers.

    --
    Randy
    Chance Favors The Prepared Mind
    comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
     
    Randy Webb, Mar 7, 2007
    #7
  8. In comp.lang.javascript message <>,
    Wed, 7 Mar 2007 08:51:12, Randy Webb <> posted:
    >Evertjan. said the following on 3/7/2007 5:06 AM:
    >> Randy Webb wrote on 07 mrt 2007 in comp.lang.javascript:
    >>
    >>> Cogito said the following on 3/6/2007 11:52 PM:
    >>>> I'm trying to understand some Javascript code from a certain site.
    >>>> Could you please tell me what does this test mean?
    >>>> if ( j%4 == 0 )
    >>>> What does %4 test for and is there a web site that explains it and,
    >>>> presumably, also %1, %2 etc.
    >>> The statement above means if the remainder of dividing j by 4 is 0.
    >>> You can change the 0 to anything smaller than j.
    >>>

    >> There is no such limitation.
    >> ;-)

    >
    >Tis true, but the results are pretty useles if k is smaller than j in j%k.


    That is certainly not true, and neither is the converse. But if j is
    *always* smaller than k, the operation is pointless.

    >> But to be useful: Anything? Also any fraction or any negative
    >>integer?

    >
    >Yes. Or at least testing doesn't throw up on fractions or negative
    >integers.


    Testing has its uses; but the standards are sufficiently clear. For
    example, -6.875%1.25 has a meaning, and the operation gives it.

    --
    (c) John Stockton, Surrey, UK. ???@merlyn.demon.co.uk Turnpike v6.05 MIME.
    Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
    In MS OE, choose Tools, Options, Send; select Plain Text for News and E-mail.
    Don't quote more than is needed, and respond after each quoted part.
     
    Dr J R Stockton, Mar 7, 2007
    #8
  9. Cogito

    Randy Webb Guest

    Dr J R Stockton said the following on 3/7/2007 11:48 AM:
    > In comp.lang.javascript message <>,
    > Wed, 7 Mar 2007 08:51:12, Randy Webb <> posted:
    >> Evertjan. said the following on 3/7/2007 5:06 AM:
    >>> Randy Webb wrote on 07 mrt 2007 in comp.lang.javascript:


    <snip>

    >>> But to be useful: Anything? Also any fraction or any negative
    >>> integer?

    >> Yes. Or at least testing doesn't throw up on fractions or negative
    >> integers.

    >
    > Testing has its uses; but the standards are sufficiently clear. For
    > example, -6.875%1.25 has a meaning, and the operation gives it.


    Yeah, the "standards" are sufficiently useless also. We all know how
    abundantly clear the "standards" are with regards to toFixed() now don't we?

    Keep the "standards", give me testing.

    --
    Randy
    Chance Favors The Prepared Mind
    comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
     
    Randy Webb, Mar 8, 2007
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sting
    Replies:
    5
    Views:
    1,634
    Natty Gur
    Jun 8, 2004
  2. Robert Allan Schwartz
    Replies:
    7
    Views:
    378
    Marco Manfredini
    Aug 13, 2004
  3. Chris
    Replies:
    1
    Views:
    671
    Chris
    May 11, 2006
  4. Edvard Majakari
    Replies:
    4
    Views:
    688
    Edvard Majakari
    Feb 25, 2005
  5. Skybuck Flying

    Call oddities: &Test() vs &Test vs Test

    Skybuck Flying, Oct 4, 2009, in forum: C Programming
    Replies:
    1
    Views:
    715
    Skybuck Flying
    Oct 4, 2009
Loading...

Share This Page