我正在使用Big.js来比较Jsp.its中的数值,在Mozilla中工作得很好,但是当我在IE中检查它时,它不能正常工作。我已经使用了下面的Big.js code.Please,回顾它,并指导我做同样的事情。
我已经从http://github.com/whatgoodisaroad/Big-js使用过这个Big.js
Big.prototype.lessThanOrEqualTo = function(right) {
var c = compare(this, right);
return c == LT || c == EQ;
};
function compare(bl, br) {
bl = bl.clone();
br = br.clone();
if (bl.sign != br.sign) {
if (bl.sign == POSITIVE) { return GT; }
else /* (bl.sign == NEGATIVE) */ { return LT; }
}
else if (bl.exponent != br.exponent) {
if (bl.sign == POSITIVE) {
if (bl.exponent > br.exponent) { return GT; }
else { return LT; }
}
else {
if (bl.exponent > br.exponent) { return LT; }
else { return GT; }
}
}
else {
var same = sameExponent(bl, br);
return bl.sign == POSITIVE ?
compareMantissae(same.l.mantissa, same.r.mantissa) :
compareMantissae(same.r.mantissa, same.l.mantissa);
}
}
// Compare only mantissae, assuming they correspond to equal
// exponents:
function compareMantissae(m1, m2) {
m1 = m1.slice();
m2 = m2.slice();
if (!m2.length) {
if (mantissaIsZero(m1)) { return EQ; }
else { return GT; }
}
else if (!m1.length) {
if (mantissaIsZero(m2)) { return EQ; }
else { return LT; }
}
if (m1[0] > m2[0]) { return GT; }
else if (m1[0] < m2[0]) { return LT; }
return compareMantissae(m1.splice(1), m2.splice(1));
}发布于 2013-08-27 20:14:02
In Big.js there are compareMantissae() function
function compareMantissae(m1, m2) {
m1 = m1.slice();
m2 = m2.slice();
if (!m2.length) {
if (mantissaIsZero(m1)) { return EQ; }
else { return GT; }
}
else if (!m1.length) {
if (mantissaIsZero(m2)) { return EQ; }
else { return LT; }
}
if (m1[0] > m2[0]) { return GT; }
else if (m1[0] < m2[0]) { return LT; }
// return compareMantissae(m1.splice(1), m2.splice(1));
return compareMantissae(m1.splice(-1*(m1.length-1),(m1.length-1)),m2.splice(-1*(m2.length-1),(m2.length-1)));
}
in this function there are change instead of
// return compareMantissae(m1.splice(1), m2.splice(1));
put this
return compareMantissae(m1.splice(-1*(m1.length-1),(m1.length-1)),m2.splice(-1*(m2.length-1),(m2.length-1)));
its working in IE(6,7,8,9),Mozilla and Chrome also.
this function works like this,
array.splice(index,howmany,item1,.....,itemX);
Parameter
index : Required. An integer that specifies at what position to add/remove items, Use negative values
to specify the position from the end of the array
howmany : Required. The number of items to be removed. If set to 0, no items will be removed
item1, ..., itemX : Optional. The new item(s) to be added to the arrayhttps://stackoverflow.com/questions/17290560
复制相似问题