Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > JavaScript does make errors when dealing just with integers

Reply
Thread Tools

JavaScript does make errors when dealing just with integers

 
 
Dr J R Stockton
Guest
Posts: n/a
 
      08-20-2008
In comp.lang.javascript message <609f1ed2-0820-4676-ba2b-505d2ab4d8b6@s5
0g2000hsb.googlegroups.com>, Tue, 19 Aug 2008 15:30:35,
posted:

>Again, THE real problem IS (and I had forgotten) is that THIS,
>tempx = parseInt(((fpssArray[i][j]).toString()).substring((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(parseFloat(((fpssArray[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.demon.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes precede replies. Snip well. Write clearly. Mail no News.
 
Reply With Quote
 
 
 
 
Dr J R Stockton
Guest
Posts: n/a
 
      08-20-2008
In comp.lang.javascript message <2ee706d9-336c-4c5c-b375-a750c37b5658@i7
6g2000hsf.googlegroups.com>, Wed, 20 Aug 2008 05:23:46, lorlarz
<> posted:
>On Aug 20, 2:11*am, Matthias Watermann <li...@mwat.de> wrote:
>> On Tue, 19 Aug 2008 15:30:35 -0700, lorlarz2 wrote:
>> > [...]
>> > The problem presently is this line:
>> > tempx = parseInt(parseFloat(((fpssArray[i]
>> > [j]).toString()).substring((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.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.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.
 
Reply With Quote
 
 
 
 
lorlarz
Guest
Posts: n/a
 
      08-21-2008
On Aug 20, 5:35*pm, Dr J R Stockton <j...@merlyn.demon.co.uk> wrote:
> In comp.lang.javascript message <2ee706d9-336c-4c5c-b375-a750c37b5658@i7
> 6g2000hsf.googlegroups.com>, Wed, 20 Aug 2008 05:23:46, lorlarz
> <lorl...@gmail.com> posted:
>
> >On Aug 20, 2:11*am, Matthias Watermann <li...@mwat.de> wrote:
> >> On Tue, 19 Aug 2008 15:30:35 -0700, lorlarz2 wrote:
> >> > [...]
> >> > The problem presently is this line:
> >> > tempx = parseInt(parseFloat(((fpssArray[i]
> >> > [j]).toString()).substring((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.demon.co.uk *Turnpike v6.05 *MIME.
> *Web *<URL:http://www.merlyn.demon.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.
 
Reply With Quote
 
lorlarz
Guest
Posts: n/a
 
      08-21-2008
On Aug 20, 7:08*pm, lorlarz <lorl...@gmail.com> wrote:
> On Aug 20, 5:35*pm, Dr J R Stockton <j...@merlyn.demon.co.uk> wrote:
>
>
>
> > In comp.lang.javascript message <2ee706d9-336c-4c5c-b375-a750c37b5658@i7
> > 6g2000hsf.googlegroups.com>, Wed, 20 Aug 2008 05:23:46, lorlarz
> > <lorl...@gmail.com> posted:

>
> > >On Aug 20, 2:11*am, Matthias Watermann <li...@mwat.de> wrote:
> > >> On Tue, 19 Aug 2008 15:30:35 -0700, lorlarz2 wrote:
> > >> > [...]
> > >> > The problem presently is this line:
> > >> > tempx = parseInt(parseFloat(((fpssArray[i]
> > >> > [j]).toString()).substring((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.demon.co.uk *Turnpikev6.05 *MIME.
> > *Web *<URL:http://www.merlyn.demon.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.
 
Reply With Quote
 
optimistx
Guest
Posts: n/a
 
      08-21-2008
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.


 
Reply With Quote
 
lorlarz
Guest
Posts: n/a
 
      08-21-2008
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.
 
Reply With Quote
 
Dr J R Stockton
Guest
Posts: n/a
 
      08-21-2008
In comp.lang.javascript message <2d695a73-eb79-43f1-9897-9dfe9b4eebef@k1
3g2000hse.googlegroups.com>, Wed, 20 Aug 2008 17:38:21, lorlarz
<> posted:
>
>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.demon.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes precede replies. Snip well. Write clearly. Mail no News.
 
Reply With Quote
 
lorlarz
Guest
Posts: n/a
 
      08-21-2008
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 incompatibilities --
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.
 
Reply With Quote
 
optimistx
Guest
Posts: n/a
 
      08-21-2008
Dr J R Stockton wrote:
> In comp.lang.javascript message
> <2d695a73-eb79-43f1-9897-9dfe9b4eebef@k1 3g2000hse.googlegroups.com>,
> Wed, 20 Aug 2008 17:38:21, lorlarz <> posted:
>>
>> 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

http://lipas.uwasa.fi/~ts/http/police.html

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.

...."






 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to avoid Out of Memory Errors when dealing with a large XML file? Saqib Ali Perl Misc 2 01-14-2011 09:31 PM
Subprocess module - communicate(data) dealing with errors Paul Moore Python 0 11-21-2006 10:51 PM
When exceptions aren't enough: Dealing with runtime errors. Aaron W. LaFramboise C++ 4 07-25-2005 04:58 AM
Errors, errors, errors Mark Goldin ASP .Net 2 01-17-2004 08:05 PM
Tips for Dealing with "Just Taylor's" SPAM Anonymous Computer Support 1 07-14-2003 03:45 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57