XNS, in keeping a close compatibility with
JavaScript, has three special XNS number types representing
Number.NaN
, Number.POSITIVE_INFINITY
, and
Number.NEGATIVE_INFINITY
. These constructors return objects
designed specifically to act as their JavaScript counterparts. Although you
theoretically could use the original values themselves, building objects from
these allows for better compatibility with XNS in my opinion.
function XNS_NaN() { }
XNS_NaN.prototype.xnsType = "NaN"
XNS_NaN.prototype.xnsVersion = "1.0"
XNS_NaN.prototype.isReal = returnFalse
(from the utility script)XNS_NaN.prototype.isDecimal = returnFalse
XNS_NaN.prototype.isRational = returnFalse
XNS_NaN.prototype.isInteger = returnFalse
XNS_NaN.prototype.isNegative = returnFalse
XNS_NaN.prototype.compareTo = function() { return Number.NaN }
XNS_NaN.prototype.negate = XNS_NaN.prototype.compareTo
XNS_NaN.prototype.add = XNS_NaN.prototype.compareTo
XNS_NaN.prototype.subtract =
XNS_NaN.prototype.compareTo
XNS_NaN.prototype.multiply =
XNS_NaN.prototype.compareTo
XNS_NaN.prototype.divide = XNS_NaN.prototype.compareTo
XNS_NaN.prototype.toString = function() { return this.xnsType }
XNS_NaN.prototype.toLiteralString = function() { return "new XNS_NaN()" }
XNS_NaN.prototype.toMathML = function() { var response = document.createElementNS(xmlns_math, "cn") response.setAttribute("type", "constant") response.appendChild(document.createEntityReference("&NotANumber;")) return response }
function XNS_Infinity() { }
XNS_Infinity.prototype.xnsType = "Infinity"
XNS_Infinity.prototype.xnsVersion = "1.0"
XNS_Infinity.prototype.isReal = returnTrue
XNS_Infinity.prototype.isDecimal = returnFalse
XNS_Infinity.prototype.isRational = returnFalse
XNS_Infinity.prototype.isInteger = returnFalse
XNS_Infinity.prototype.isNegative = returnFalse
XNS_Infinity.prototype.compareTo = function(that) { switch (true) { case (that.xnsType == "Infinity"): case ((that.xnsType == "Number")&&(that == Infinity)): return 0 case (that.xnsType != "-Infinity"): return -1 } return new XNS_NaN() }
XNS_Infinity.prototype.negate = function() { return new XNS_NEG_Infinity() }
XNS_Infinity.prototype.add = function(that) { switch (true) { case (that.xnsType == "NaN"): case (that.xnsType == "-Infinity"): return new XNS_NaN() } return new XNS_Infinity() }
XNS_Infinity.prototype.subtract = function(that) { switch (true) { case (that.xnsType == "NaN"): case (that.xnsType == "Infinity"): return new XNS_NaN() } return new XNS_Infinity() }
XNS_Infinity.prototype.multiply = function(that) { switch (true) { case (!that.isReal()): case (that.compareTo(0) == 0): return new XNS_NaN() case (that.isNegative()): return new XNS_NEG_Infinity() } return new XNS_Infinity() }
XNS_Infinity.prototype.divide = function(that) { switch (true) { case (!that.isReal()): case (that.xnsType == "Infinity"): case (that.xnsType == "-Infinity"): return new XNS_NaN() case (that.isNegative()): return new XNS_NEG_Infinity() } return new XNS_Infinity() }
XNS_Infinity.prototype.toString = function() { return this.xnsType }
XNS_Infinity.prototype.toLiteralString = function() { return "new XNS_Infinity()" }
XNS_Infinity.prototype.toMathML = function() { var response = document.createElementNS(xmlns_math, "cn") response.setAttribute("type", "constant") response.appendChild(document.createEntityReference("∞")) return response }
function XNS_NEG_Infinity() { }
XNS_NEG_Infinity.prototype.xnsType = "-Infinity"
XNS_NEG_Infinity.prototype.xnsVersion = "1.0"
XNS_NEG_Infinity.prototype.isReal = returnTrue
XNS_NEG_Infinity.prototype.isDecimal = returnFalse
XNS_NEG_Infinity.prototype.isRational = returnFalse
XNS_NEG_Infinity.prototype.isInteger = returnFalse
XNS_NEG_Infinity.prototype.isNegative = returnFalse
XNS_NEG_Infinity.prototype.compareTo = function(that) { switch (true) { case (that.xnsType == "-Infinity"): case ((that.xnsType == "Number")&&(that == -Infinity)): return 0 case (that.xnsType != "-Infinity"): return -1 } return new XNS_NaN() }
XNS_NEG_Infinity.prototype.negate = function() { return new XNS_Infinity() }
XNS_NEG_Infinity.prototype.add = function(that) { switch (true) { case (that.xnsType == "NaN"): case (that.xnsType == "Infinity"): return new XNS_NaN() } return new XNS_Infinity() }
XNS_NEG_Infinity.prototype.subtract = function(that) { switch (true) { case (that.xnsType == "NaN"): case (that.xnsType == "-Infinity"): return new XNS_NaN() } return new XNS_Infinity() }
XNS_NEG_Infinity.prototype.multiply = function(that) { switch (true) { case (!that.isReal()): case (that.compareTo(0) == 0): return new XNS_NaN() case (!that.isNegative()): return new XNS_NEG_Infinity() } return new XNS_Infinity() }
XNS_NEG_Infinity.prototype.divide = function(that) { switch (true) { case (!that.isReal()): case (that.xnsType == "Infinity"): case (that.xnsType == "-Infinity"): return new XNS_NaN() case (!that.isNegative()): return new XNS_NEG_Infinity() } return new XNS_Infinity() }
XNS_NEG_Infinity.prototype.toString = function() { return this.xnsType }
XNS_NEG_Infinity.prototype.toLiteralString = function() { return "new XNS_NEG_Infinity()" }
XNS_Infinity.prototype.toMathML = function() { var response = document.createElementNS(xmlns_math, "apply") var minus = document.createElementNS(xmlns_math, "minus") response.appendChild(minus) var cn = document.createElementNS(xmlns_math, "cn") cn.setAttribute("type", "constant") cn.appendChild(document.createEntityReference("∞")) response.appendChild(cn) return response }