Opera JavaScript Flaw--Computation Error

This page demonstrates what appears to be a flaw in the Opera 3.0 browser's JavaScript implementation. This page is a simplified example based on the original application where the flaw was discovered. The original application is a geodetic distance calculator.

The example below contains two nearly identical computations that should provide the same result. When this page is loaded in Opera 3.0, however, the results differ. In the second computation (see the source below), the multiplication by R is omitted.


Source

Here is a view of the JavaScript source. The script's results will be displayed in the next section.

<SCRIPT LANGUAGE="JavaScript">

    <!--

    var x1 = 1.518436449235;
    var y1 = 0.5759586531581;
    var x2 = 1.535889741755;
    var y2 = 0.5934119456781;
    var R = 6378137.0;
    var dist;

    // First computation (evaluates correctly)
    dist = R * (Math.acos (Math.sin (y1) * Math.sin (y2)
           + Math.cos (y1) * Math.cos (y2) * Math.cos (x1-x2)));

    document.write ("<P><STRONG>First computation:</STRONG> dist = " + dist);

    // Second computation (does not evaluate correctly)
    dist = (Math.acos (Math.sin (y1) * Math.sin (y2)
           + Math.cos (y1) * Math.cos (y2) * Math.cos (x1-x2))) * R;

    document.write ("<P><STRONG>Second computation:</STRONG> dist = " + dist);

    //     -->

</SCRIPT>

Results

The results of the script appear below (provided you have JavaScript enabled). The numbers should be the same, but in Opera 3.0, they are different (the second result is incorrect).


Discovered By

This flaw was discovered by Charles L. Taylor, who also prepared this example.


Last update: 10 Oct 1999 -- (Copyright) -- (Contact)