JavaScript does make errors when dealing just with integers

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve Swift

    #31
    Re: JavaScript does make errors when dealing just with integers

    lorlarz wrote:
    Without adding on an arbitrary decimal number less than one (I believe
    I use .9) ,
    Computers use binary. Would you tell us the *precise* value of 0.9 in
    binary, please?

    --
    Steve Swift


    Comment

    • Matthias Watermann

      #32
      Re: JavaScript does make errors when dealing just with integers

      On Tue, 19 Aug 2008 15:30:35 -0700, lorlarz2 wrote:
      [...]
      The problem presently is this line:
      tempx = parseInt(parseF loat(((fpssArra y[i]
      [j]).toString()).s ubstring((m*3), (m*3)+3)) + .9);
      I'd suggest to read (and try to understand) the docs of "parseInt() "
      especially the meaning (and consequence) of the second (radix) argument.

      --
      Matthias
      /"\
      \ / ASCII RIBBON CAMPAIGN - AGAINST HTML MAIL
      X - AGAINST M$ ATTACHMENTS
      / \

      Comment

      • The Magpie

        #33
        Re: JavaScript does make errors when dealing just with integers

        Stevo wrote:
        lorlarz wrote:
        >Contrary to what one authority in the JavaScript field says:
        >JavaScript does make errors when dealing with just with integers.
        >I use .9) ,
        >
        Funny looking integer.
        Yeah, I thought that too...

        Comment

        • lorlarz

          #34
          Re: JavaScript does make errors when dealing just with integers

          On Aug 20, 2:11 am, Matthias Watermann <li...@mwat.dew rote:
          On Tue, 19 Aug 2008 15:30:35 -0700, lorlarz2 wrote:
          [...]
          The problem presently is this line:
          tempx = parseInt(parseF loat(((fpssArra y[i]
          [j]).toString()).s ubstring((m*3), (m*3)+3)) + .9);
          >
          I'd suggest to read (and try to understand) the docs of "parseInt() "
          especially the meaning (and consequence) of the second (radix) argument.
          >
          --
                  Matthias
              /"\
              \ /    ASCII RIBBON CAMPAIGN - AGAINST HTML MAIL
               X                           - AGAINST M$ ATTACHMENTS
              / \
          True. Adding the "optional" radix (base) argument fixes the problem:
          In

          change
          tempx = parseInt(((fpss Array[i][j]).toString()).s ubstring((m*3),
          (m*3)+3)); TO

          tempx = parseInt(((fpss Array[i][j]).toString()).s ubstring((m*3),
          (m*3)+3),10);

          and the problem seems fixed without the workaround I previously used.

          This is verified by Cornford in the other thread on this.

          The base is NOT optional because of "features" of the parseInt
          function,
          seeing things as octal if they begin with zero and then not
          recognizing the
          digits 8 and 9.

          Thanks.

          Comment

          • Dr J R Stockton

            #35
            Re: JavaScript does make errors when dealing just with integers

            In comp.lang.javas cript message <609f1ed2-0820-4676-ba2b-505d2ab4d8b6@s5
            0g2000hsb.googl egroups.com>, Tue, 19 Aug 2008 15:30:35,
            lorlarz2@gmail. com posted:
            >Again, THE real problem IS (and I had forgotten) is that THIS,
            >tempx = parseInt(((fpss Array[i][j]).toString()).s ubstring((m*3),
            >(m*3)+3));
            >does NOT work.



            When claiming that something does not work, state which versions of
            which browsers you are using, and what if anything their debug
            facilities gave you. If you mean that it gave a "wrong" answer, say
            what the data and the "incorrect" and hoped-for answers were. If it
            gave an error message, say what that was.

            For a helpful demonstration, include code to set i j fpssArray[i][j] and
            m to known values, and state what you expect and what you actually get.
            Use copy'n'paste to ensure faithfulness. When coding, omit superfluous
            parentheses and indent in two-space units to show the intended logical
            structure. My js-quick.htm will give a first approximation to rational
            indentation.

            And give your real name and whereabouts when posting, unless you want to
            make people think that you are ashamed of your work. And follow other
            traditional Usenet conventions too - see sig.

            Re your original line
            tempx = parseInt(parseF loat(((fpssArra y[i][j]).toString()).
            substring((m*3) ,(m*3)+3)) + .9);

            One should never use a decimal point without at least one digit on each
            side. When reading it, the computer will read it reliably; a human may
            not.

            Whatever that line is meant to do (assuming toString() is needed), it
            does seem to convert a Number to a Number. That can more effectively be
            done by purely numeric operations. parseInt should not be used instead
            of Math.floor or |0. To convert a decimal digit string to a Number,
            unary + is most effective.


            --
            (c) John Stockton, nr London UK. replyYYWW merlyn demon co uk Turnpike 6.05.
            Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html-Timo Salmi: Usenet Q&A.
            Web <URL:http://www.merlyn.demo n.co.uk/news-use.htm: about usage of News.
            No Encoding. Quotes precede replies. Snip well. Write clearly. Mail no News.

            Comment

            • Dr J R Stockton

              #36
              Re: JavaScript does make errors when dealing just with integers

              In comp.lang.javas cript message <2ee706d9-336c-4c5c-b375-a750c37b5658@i7
              6g2000hsf.googl egroups.com>, Wed, 20 Aug 2008 05:23:46, lorlarz
              <lorlarz@gmail. composted:
              >On Aug 20, 2:11 am, Matthias Watermann <li...@mwat.dew rote:
              >On Tue, 19 Aug 2008 15:30:35 -0700, lorlarz2 wrote:
              [...]
              The problem presently is this line:
              tempx = parseInt(parseF loat(((fpssArra y[i]
              [j]).toString()).s ubstring((m*3), (m*3)+3)) + .9);
              >>
              >I'd suggest to read (and try to understand) the docs of "parseInt() "
              >especially the meaning (and consequence) of the second (radix) argument.
              >>
              >--
              >        Matthias
              >...
              Signatures should not be quoted, unless being discussed.
              >True. Adding the "optional" radix (base) argument fixes the problem:
              If you had read the newsgroup FAQ before posting, as FAQ 2.3 enjoins,
              you would have seen in FAQ 4.12 both that and why a second parameter
              should ALWAYS be considered for parseInt. You would also have realised
              that almost all of us here already knew that, whether by reading the FAQ
              or otherwise.

              And if you had read FAQ 4.21, you might have realised not only that a
              second parameter for parseInt is often needed, but that unary + will
              serve in most cases including AFAICS yours.

              One of the purposes of a newsgroup FAQ is to pre-empt unnecessary posts
              from the more intelligent ignorami.

              Of course, any serious JavaScript programmer should be reasonably
              familiar with the content of ISO/IEC 16262:2002(E) /* or ...(?) */;
              Section 15.1.2.2 refers.

              Nevertheless, I still believe that, if the array holds Number values,
              then you^H^H^Hone could extract the desired Number value more
              effectively by arithmetic. If it holds only Strings, .toString() is
              superfluous.


              By the way, any recommendation of "Crockford' s Book" should
              include a warning against going into the better sort of bookshop
              and just asking for "Crockford" . Outside the present context,
              John's book is more widely known than Doug's, as any Vicar
              should be able to confirm.

              Opera is 9.52.

              --
              (c) John Stockton, nr London UK. ???@merlyn.demo n.co.uk Turnpike v6.05 MIME.
              Web <URL:http://www.merlyn.demo n.co.uk/- FAQish topics, acronyms, & links.
              Check boilerplate spelling -- error is a public sign of incompetence.
              Never fully trust an article from a poster who gives no full real name.

              Comment

              • lorlarz

                #37
                Re: JavaScript does make errors when dealing just with integers

                On Aug 20, 5:35 pm, Dr J R Stockton <j...@merlyn.de mon.co.ukwrote:
                In comp.lang.javas cript message <2ee706d9-336c-4c5c-b375-a750c37b5658@i7
                6g2000hsf.googl egroups.com>, Wed, 20 Aug 2008 05:23:46, lorlarz
                <lorl...@gmail. composted:
                >
                On Aug 20, 2:11 am, Matthias Watermann <li...@mwat.dew rote:
                On Tue, 19 Aug 2008 15:30:35 -0700, lorlarz2 wrote:
                [...]
                The problem presently is this line:
                tempx = parseInt(parseF loat(((fpssArra y[i]
                [j]).toString()).s ubstring((m*3), (m*3)+3)) + .9);
                >
                I'd suggest to read (and try to understand) the docs of "parseInt() "
                especially the meaning (and consequence) of the second (radix) argument.
                >
                --
                        Matthias
                ...
                >
                Signatures should not be quoted, unless being discussed.
                >
                True.  Adding the "optional" radix (base) argument fixes the problem:
                >
                If you had read the newsgroup FAQ before posting, as FAQ 2.3 enjoins,
                you would have seen in FAQ 4.12 both that and why a second parameter
                should ALWAYS be considered for parseInt.  You would also have realised
                that almost all of us here already knew that, whether by reading the FAQ
                or otherwise.
                >
                And if you had read FAQ 4.21, you might have realised not only that a
                second parameter for parseInt is often needed, but that unary + will
                serve in most cases including AFAICS yours.
                >
                One of the purposes of a newsgroup FAQ is to pre-empt unnecessary posts
                from the more intelligent ignorami.
                >
                Of course, any serious JavaScript programmer should be reasonably
                familiar with the content of ISO/IEC 16262:2002(E) /* or ...(?) */;
                Section 15.1.2.2 refers.
                >
                Nevertheless, I still believe that, if the array holds Number values,
                then you^H^H^Hone could extract the desired Number value more
                effectively by arithmetic.  If it holds only Strings, .toString() is
                superfluous.
                >
                        By the way, any recommendation of "Crockford' s Book" should
                        include a warning against going into the better sort of bookshop
                        and just asking for "Crockford" .  Outside the present context,
                        John's book is more widely known than Doug's, as any Vicar
                        should be able to confirm.
                >
                Opera is 9.52.
                >
                --
                (c) John Stockton, nr London UK.  ?...@merlyn.dem on.co.uk  Turnpike v6.05  MIME.
                 Web  <URL:http://www.merlyn.demo n.co.uk/- FAQish topics, acronyms,& links.
                     Check boilerplate spelling -- error is a public sign of incompetence.
                    Never fully trust an article from a poster who gives no full realname.
                Sorry I didn't read everything. Not too sorry, though.

                You are also correct that the toString is superfluous since the
                fpssArray element does
                hold a string.
                I did not do everything perfectly correctly 4 years ago, when the
                program was written.
                (Of course I do now.)

                But, I suspect I do some things few others in this newsgroup do
                nowadays and I do them
                well, as well.

                Comment

                • lorlarz

                  #38
                  Re: JavaScript does make errors when dealing just with integers

                  On Aug 20, 7:08 pm, lorlarz <lorl...@gmail. comwrote:
                  On Aug 20, 5:35 pm, Dr J R Stockton <j...@merlyn.de mon.co.ukwrote:
                  >
                  >
                  >
                  In comp.lang.javas cript message <2ee706d9-336c-4c5c-b375-a750c37b5658@i7
                  6g2000hsf.googl egroups.com>, Wed, 20 Aug 2008 05:23:46, lorlarz
                  <lorl...@gmail. composted:
                  >
                  >On Aug 20, 2:11 am, Matthias Watermann <li...@mwat.dew rote:
                  >On Tue, 19 Aug 2008 15:30:35 -0700, lorlarz2 wrote:
                  [...]
                  The problem presently is this line:
                  tempx = parseInt(parseF loat(((fpssArra y[i]
                  [j]).toString()).s ubstring((m*3), (m*3)+3)) + .9);
                  >
                  >I'd suggest to read (and try to understand) the docs of "parseInt() "
                  >especially the meaning (and consequence) of the second (radix) argument.
                  >
                  >--
                  >        Matthias
                  >...
                  >
                  Signatures should not be quoted, unless being discussed.
                  >
                  >True.  Adding the "optional" radix (base) argument fixes the problem:
                  >
                  If you had read the newsgroup FAQ before posting, as FAQ 2.3 enjoins,
                  you would have seen in FAQ 4.12 both that and why a second parameter
                  should ALWAYS be considered for parseInt.  You would also have realised
                  that almost all of us here already knew that, whether by reading the FAQ
                  or otherwise.
                  >
                  And if you had read FAQ 4.21, you might have realised not only that a
                  second parameter for parseInt is often needed, but that unary + will
                  serve in most cases including AFAICS yours.
                  >
                  One of the purposes of a newsgroup FAQ is to pre-empt unnecessary posts
                  from the more intelligent ignorami.
                  >
                  Of course, any serious JavaScript programmer should be reasonably
                  familiar with the content of ISO/IEC 16262:2002(E) /* or ...(?) */;
                  Section 15.1.2.2 refers.
                  >
                  Nevertheless, I still believe that, if the array holds Number values,
                  then you^H^H^Hone could extract the desired Number value more
                  effectively by arithmetic.  If it holds only Strings, .toString() is
                  superfluous.
                  >
                          By the way, any recommendation of "Crockford' s Book" should
                          include a warning against going into the better sort ofbookshop
                          and just asking for "Crockford" .  Outside the presentcontext,
                          John's book is more widely known than Doug's, as any Vicar
                          should be able to confirm.
                  >
                  Opera is 9.52.
                  >
                  --
                  (c) John Stockton, nr London UK.  ?...@merlyn.dem on.co.uk  Turnpikev6.05  MIME.
                   Web  <URL:http://www.merlyn.demo n.co.uk/- FAQish topics, acronyms, & links.
                       Check boilerplate spelling -- error is a public sign of incompetence.
                      Never fully trust an article from a poster who gives no full real name.
                  >
                  Sorry I didn't read everything.  Not too sorry, though.
                  >
                  You are also correct that the toString is superfluous since the
                  fpssArray element does
                  hold a string.
                  I did not do everything perfectly correctly 4 years ago, when the
                  program was written.
                  (Of course I do now.)
                  >
                  But, I suspect I do some things few others in this newsgroup do
                  nowadays and I do them
                  well, as well.
                  Dr J R Stockton

                  Actually, I wrote the JS scorer 5 years ago, I just checked. No
                  wonder I did not
                  recall the details of my troubles. Still, I should have refreshed
                  better and
                  looked at the details and given a bit more thought, and I could likely
                  have
                  caught the parseInt problem (actually my problem in the way I used
                  parseInt)
                  myself. I am more sorry for that than not reading the FAQ of this
                  newsgroup.
                  Here's why:

                  Frankly, there are quite a few ".9 people" (if you know
                  what I mean) HERE who never seem to read, look, or think
                  clearly. They like to try to pounce or pile on, usually failing.
                  And, their complaints
                  seem so vague they seem to be more due to their confusion and
                  ignorance and inability to understand than their supposed concerns
                  with "clarity" or "quality".

                  In short, contrary to what you indicate, this newsgroup
                  did (and does) not appear to be as sophisticated a newsgroup
                  as you say. Probably just wishful thinking, on your part.
                  I would have guessed the FAQ would have been less.

                  Let me say a bit more:
                  The frustration these ".9ers" have with my fine JavaScript
                  Applications (PROGRAMS) seems to relate not only to the
                  fact they have never done one (and perhaps never seen one)
                  but to this lack of sophistication (and knowledge).
                  Those things and jealousy, of course.

                  When more can show their programs, I will shut up and
                  learn from such. Believe me. I get busy when I have
                  something to be busy with. I would love to have
                  something better to do than just read drivel here.

                  Comment

                  • optimistx

                    #39
                    Re: JavaScript does make errors when dealing just with integers

                    lorlarz wrote:
                    ....
                    When more can show their programs, I will shut up and
                    learn from such. Believe me. I get busy when I have
                    something to be busy with. I would love to have
                    something better to do than just read drivel here.
                    I have been wondering also whether the active posters here really have
                    written 'long programs' (e.g. at least some hundreds of lines), which they
                    are proud of and which would be appreciated here by the experts of the
                    newsgroup. It is easy to complain about everything what Microsoft and others
                    have done, but it might be difficult to show 'Here is a long javascript
                    program , which in our opinion is a good example for any javascript newbie
                    to learn about.'

                    I downloaded 'Fork', written by Peter Michaux. Fork resembles Yahoo and
                    Mootools (according to Peter as far as I can remember). Opinions about this
                    framework? (a new thread can be started about this.


                    Comment

                    • lorlarz

                      #40
                      Re: JavaScript does make errors when dealing just with integers

                      On Aug 21, 3:04 am, "optimistx" <optimistxPoi.. .@poistahotmail .com>
                      wrote:
                      lorlarz wrote:
                      >
                      ...
                      >
                      When more can show their programs, I will shut up and
                      learn from such.  Believe me.  I get busy when I have
                      something to be busy with.  I would love to have
                      something better to do than just read drivel here.
                      >
                      I have been wondering also whether the active posters here really have
                      written 'long programs' (e.g. at least some hundreds of lines), which they
                      are proud of and which would be appreciated here by the experts of the
                      newsgroup. It is easy to complain about everything what Microsoft and others
                      have done, but it might be difficult to show 'Here is a long javascript
                      program  , which in our opinion is a good example for any javascript newbie
                      to learn about.'
                      >
                      I downloaded 'Fork', written by Peter Michaux. Fork resembles Yahoo and
                      Mootools (according to Peter as far as I can remember). Opinions about this
                      framework? (a new thread can be started about this.
                      I am glad someone else is wondering. I can tell you that I would
                      love
                      to hear about and examine other peoples' good full javascript
                      programs (applications). I have processed ALL of them that has
                      ever been in a book written in English 1999- the present.
                      But, good large neat examples
                      of applications seems to have dried up.

                      Comment

                      • lorlarz

                        #41
                        Re: JavaScript does make errors when dealing just with integers

                        On Aug 21, 3:04 am, "optimistx" <optimistxPoi.. .@poistahotmail .com>
                        wrote:
                        lorlarz wrote:
                        >
                        ...
                        >
                        When more can show their programs, I will shut up and
                        learn from such.  Believe me.  I get busy when I have
                        something to be busy with.  I would love to have
                        something better to do than just read drivel here.
                        >
                        I have been wondering also whether the active posters here really have
                        written 'long programs' (e.g. at least some hundreds of lines), which they
                        are proud of and which would be appreciated here by the experts of the
                        newsgroup. It is easy to complain about everything what Microsoft and others
                        have done, but it might be difficult to show 'Here is a long javascript
                        program  , which in our opinion is a good example for any javascript newbie
                        to learn about.'
                        >
                        I downloaded 'Fork', written by Peter Michaux. Fork resembles Yahoo and
                        Mootools (according to Peter as far as I can remember). Opinions about this
                        framework? (a new thread can be started about this.
                        About Peter's framework: I have not looked at it. I really have
                        only
                        learned jQuery and liked it for some things. The truth is, having
                        done JavaScript from scratch with no libraries for a whole decade,
                        I rarely use any library, if I already know routines. (There really
                        is very little one has to do to develop one's own mini-mini-library
                        to
                        take care of all DOM and browser and platform incompatibiliti es --
                        though admittedly some of those routines I got from others). In all
                        my
                        applications, I have used a library only once -- for it greatly
                        simplified doing callbacks on a sort of custom event and I did not
                        want
                        to have to do all that from scratch. JQuery made doing this complex
                        drag-and-drop builder program easy (did it in a couple of days; by
                        myself
                        perhaps weeks would have been involved.

                        Comment

                        • Dr J R Stockton

                          #42
                          Re: JavaScript does make errors when dealing just with integers

                          In comp.lang.javas cript message <2d695a73-eb79-43f1-9897-9dfe9b4eebef@k1
                          3g2000hse.googl egroups.com>, Wed, 20 Aug 2008 17:38:21, lorlarz
                          <lorlarz@gmail. composted:
                          >
                          >Frankly, there are quite a few ".9 people" (if you know
                          >what I mean) HERE who never seem to read, look, or think
                          >clearly.
                          Agreed. You are clearly one of them.

                          --
                          (c) John Stockton, nr London UK. replyYYWW merlyn demon co uk Turnpike 6.05.
                          Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html-Timo Salmi: Usenet Q&A.
                          Web <URL:http://www.merlyn.demo n.co.uk/news-use.htm: about usage of News.
                          No Encoding. Quotes precede replies. Snip well. Write clearly. Mail no News.

                          Comment

                          • optimistx

                            #43
                            Re: JavaScript does make errors when dealing just with integers

                            Dr J R Stockton wrote:
                            In comp.lang.javas cript message
                            <2d695a73-eb79-43f1-9897-9dfe9b4eebef@k1 3g2000hse.googl egroups.com>,
                            Wed, 20 Aug 2008 17:38:21, lorlarz <lorlarz@gmail. composted:
                            >>
                            >Frankly, there are quite a few ".9 people" (if you know
                            >what I mean) HERE who never seem to read, look, or think
                            >clearly.
                            >
                            Agreed. You are clearly one of them.
                            In your signature there are good and interesting links e.g. to prof. Timo
                            Salmi's pages



                            and somebody there is asking:

                            "Timo, given the abuse by some users, I don't know why you are still so
                            friendly to the people on the Usenet news and point them to the right
                            directions."

                            and he answers

                            "Thank you. Truthfully, however, I do not always manage to moderate my tone,
                            even if I should. However, when I do it is based on a long-time experience
                            on the Usenet news. Given the great number of readers in the international
                            newsgroups there are bound to also be abusive reactions to any advice one
                            gives. Nothing is gained by getting excessively upset about such cases.

                            ...."






                            Comment

                            Working...