XNS is a subproject of http://mozcalc.mozdev.org (MozCalc), aimed primarily at creating a JavaScript-based set of object constructor functions for handling most common kinds of numbers found in algebra. By permitting the existence of these numbers to extend the Mozilla browser's standard JavaScript Number() definitions, XNS should make the exact calculation of numbers a possibility.
JavaScript numbers, as currently implemented, reflect the IEEE 754 standard. This is a binary floating-point number standard, typically used for speed of calculations. However, such a system has definite limitations. If I ask JavaScript, "What's 1 divided by 3?", it will typically respond "0.3333333333333333". This is wrong. The number JavaScript returns is an approximation of 1 divided by 3. It also restricts the approximation's length to 16 significant digits. Beyond that 16th digit, you can effectively forget about accuracy.
Furthermore, since we are referring to a binary number system, realize that even a simple number such as 0.1 cannot be exactly represented in the binary numbers. I wrote the following script as a demonstration of this for my book, the JavaScript Developer's Dictionary.
for (x = 0; x < 1; x += .1) { document.write(x + “<br />”) } /* This returns the following: 0 0.1 0.2 0.30000000000000004 0.4 0.5 0.6 0.7 0.7999999999999999 0.8999999999999999 0.9999999999999999 */
Such a simple algorithm, outputting 11 answers instead of 10 as you would
logically expect. Although JavaScript does provide the ability to correct for
this via the Math.round()
function, the simple necessity of such
an action flies in the face of common arithmetic.
XNS revolves around several constructor functions, which return specially-formatted JavaScript objects. These objects are not JavaScript numbers per se, but include methods for comparison and arithmetic that allow them to mimic real (and sometimes "unreal" numbers -- see the XNS Complex() documentation) numbers exactly.
XNS will include, by default, the following types of numbers:
Math.sqrt(-1)
.NaN
,
Infinity
, and -Infinity
values in
JavaScript.XNS will also include in its scripting the ability to convert from one type to another upon demand, as needed. XNS may include in future editions the ability to specify variables and mathematical functions as objects (though these are not guaranteed at this point). It is my hope that XNS may also combine with JavaScripts reading content MathML to process arithmetic and algebra. Also, because these types are predefined via collections of JavaScript functions, you may want to write additional function libraries to enable additional types of numbers (such as hypercomplex numbers, or transfinite numbers).
XNS also has a utility script for providing basic functionality across the entire XNS suite.
I am primarily writing XNS for use in the Mozilla browser suite from http://www.mozilla.org, under the Mozilla tri-license scheme. It is my plan to introduce XNS as a component of the MozCalc project, which hopefully may become an extension to or part of the Mozilla browser suite.
XNS currently plans to follow a specific format for all constructor functions. Though this format is not yet "in stone", the basics are pretty simple: be able to convert to and from ordinary JavaScript numbers with no trouble, and handle arithmetic and comparison accurately. For the specifics, see the XNS Requirements page.