XNS Requirements
XNS currently has a long list of requirements
before a number type is acceptable for usage in XNS.
- A single JavaScript function shall be defined as a constructor
function, specifically to build the desired XNS number type in an object-oriented
manner.
- The function must be able to accept at least three argument sets. The
first argument set is of a single JavaScript number value, which will be
mathematically equivalent in that XNS type's number system to the
original argument. The second argument set is of a single XNS number
identical in type to the XNS type being constructed, in which case the
function must return an equal but entirely independent XNS number: none
of the properties when changed in the original may affect the copy. The
third argument set is of a single argment which is a valid XNS number
type, for which the appropriate conversion function must be called.
- Any XNS number constructed must have the following properties and
methods prototyped in, with appropriate arguments required:
- this.xnsType: A unique string to identify the constructor function
by name (the exceptions being for "NaN", "Infinity" and "-Infinity",
which are reserved)
- this.xnsVersion: A number identifying the XNS version number of the
XNS number type.
- this.isReal(): A function to return true if this represents a real
number, or false otherwise.
- this.isDecimal(): A function to return true if this represents a
decimal number, or false otherwise.
- this.isRational(): A function to return true if this represents a
rational number, or false otherwise.
- this.isInteger(): A function to return true if this represents an
integer, or false otherwise.
- this.isNegative(): A function to return true if this is less than
zero, or false otherwise.
- this.compareTo(that): If this < that, return -1. If this ==
that, return 0. If this > that, return 1. If none of the preceding
three conditions are true, return Number.NaN.
- this.negate(): Return this * -1 as a new XNS number.
- this.add(that): Return this + that as a new XNS number.
- this.subtract(that): Return this - that as a new XNS number.
- this.multiply(that): Return this * that as a new XNS number.
- this.divide(that): Return this / that as a new XNS number.
- this.toString(): Returns a simple string representation of the
number, typically for human comprehension.
- this.toLiteralString(): Returns a string representation of the
function needed to reconstruct this as a new number of the same type
and value.
- this.toMathML(): Returns a MathML element as a DOM object,
equivalent to the value of the this object. The returned element will
be content markup, as will its descendant elements.
- The XNS number type shall also provide a method of the Number function
which directly references the constructor function. It must match the
constructor function's name, prefixed by the characters "_to". For
instance, Number._toBigDecimal() referencing the BigDecimal() constructor
function.
- Any XNS number constructed (including those constructed through
arithmetic operations) must be returned in the simplest types possible,
unless there are practical reasons not to do so. This includes returning
a different type of number for the same value. For instance, a Fraction()
number where the numerator and the denominator are both equal to 3 should
return as a BigDecimal() type or a Number() type equal to 1, instead of a
Fraction type().
- The constructor function must be registered via the XNS_Types[] array
with a numerical value. (Note: This is currently not implemented with
any XNS number type.) The numerical value for Number() is reserved
at 1. The next highest shall be for the number type which is next in line
for conversions. This will be explained in detail in a future revision of
this document. Any number wishing to be excluded from conversions must
set its property name as the name for an XNS_Types[] array property, and
the value for that property as false.
- The XNS number system must conform as closely as possible to the
JavaScript1.5 implementation in Mozilla browsers. For instance, 1 / 0 in
Mozilla is currently considered equal to +Infinity. Thusly, any XNS
number equal to 1 divided by any XNS number equal to 0 must return
+Infinity.
- The XNS number type must treat XNS numbers with the XNS types of "NaN",
"Infinity", and "-Infinity" as equivalent to Number.NaN, +Infinity, and
-Infinity, respectively. This requirement does not exclude the number
type from treating JavaScript number values, which have an xnsType
property of "Number", as NaN, +Infinity, and -Infinity, when those values
are given.
Back to the XNS Main Page.
docs/Requirements.html version 1.0 created May 22, 2002