JavaScript does make errors when dealing just with integers

D

Dr J R Stockton

In comp.lang.javascript message <609f1ed2-0820-4676-ba2b-505d2ab4d8b6@s5
0g2000hsb.googlegroups.com>, Tue, 19 Aug 2008 15:30:35,
(e-mail address removed) posted:
Again, THE real problem IS (and I had forgotten) is that THIS,
tempx = parseInt(((fpssArray[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[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[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.
 
D

Dr J R Stockton

In comp.lang.javascript message <2ee706d9-336c-4c5c-b375-a750c37b5658@i7
6g2000hsf.googlegroups.com>, Wed, 20 Aug 2008 05:23:46, lorlarz
[...]
The problem presently is this line:
tempx = parseInt(parseFloat(((fpssArray
[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.


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.
 
L

lorlarz

In comp.lang.javascript message <2ee706d9-336c-4c5c-b375-a750c37b5658@i7
6g2000hsf.googlegroups.com>, Wed, 20 Aug 2008 05:23:46, lorlarz
]
The problem presently is this line:
tempx = parseInt(parseFloat(((fpssArray
[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.


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.  [email protected]  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.
 
L

lorlarz

In comp.lang.javascript message <2ee706d9-336c-4c5c-b375-a750c37b5658@i7
6g2000hsf.googlegroups.com>, Wed, 20 Aug 2008 05:23:46, lorlarz
<[email protected]> posted:
]
The problem presently is this line:
tempx = parseInt(parseFloat(((fpssArray
[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.

Signatures should not be quoted, unless being discussed.
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.  [email protected]  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.
 
O

optimistx

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.
 
L

lorlarz

lorlarz wrote:

...


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.
 
D

Dr J R Stockton

In comp.lang.javascript message <2d695a73-eb79-43f1-9897-9dfe9b4eebef@k1
3g2000hse.googlegroups.com>, Wed, 20 Aug 2008 17:38:21, lorlarz
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.
 
L

lorlarz

lorlarz wrote:

...


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.
 
O

optimistx

Dr said:
In comp.lang.javascript message


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.

...."
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top