JavaScript flubs one of three Rs. A Web
developer recently ran across an interesting arithmetic problem: When the latest versions
of Microsoft Internet Explorer and Netscape Communicator run JavaScript, certain numbers
do not multiply correctly.

The errors are small. But users seldom go back and check computer math, so wrong
answers might go unnoticed.

The example used on the Web site multiplies 81.66 by 15. The result should be 1224.9.
But Explorer 4.02 reports the answer as 1224.8999999999998, and Navigator 4.05 reports it
as 1224.8999999999999.

In the GCN Lab’s tests, the problem seemed evident only for numbers between 66.67
and 266.66 when multiplied by another number—15 in the example. We found that using
numbers such as 2.5, 5, 7.5, 30 and 60 resulted in incorrect answers, but using numbers
such as 3 and 45 did not.

The error stems from the fact that JavaScript asks the host system’s libraries to
handle the math. JavaScript handles the conversions between binary and decimal formats,
using complex algorithms optimized to give fairly accurate results. There is an Institute
of Electrical and Electronics Engineers standard for such floating-point operations, but
not everyone follows it yet.

The lab has no workaround, and no one knows what the long-term effects will be, but
anyone using JavaScript for on-screen arithmetic in Web forms should be careful.

To find out how your browser handles the problem and more information, go to

Hear no evil, speak no evil, e-mail no evil? A
colleague who phoned Microsoft Corp. technical support about the problem above was told
that it had been covered in an article in Microsoft’s Knowledge Base, the
Encyclopedia Galactica of Microsoft technical information. When the colleague asked the
Microsoft employee to e-mail the Knowledge Base article, the employee said he no longer
had access to outside e-mail. It seems so many viruses were coming in via outside e-mail
that some departments have simply shut it down, he said.

Microsoft evidently has not heard of antivirus software. Maybe that’s why it
hasn’t taken over that market yet.

The Web Surfin’ Blues. Great blues musicians used
to say it was essential to suffer broken hearts, lost jobs and hard living to sing the
blues. Now all they have to do is surf the Web. A recent psychological study, partly
funded by the National Science Foundation, found that Internet use increases feelings of
depression and loneliness. The study’s authors believe the results may be explained
by the transient nature of online relationships and neglect of face-to-face interaction.

How long before there’s a Prozac plug-in for browsers?

—Jason Byrne

Stay Connected

Sign up for our newsletter.

I agree to this site's Privacy Policy.