0

我正在使用 Big.js 比较 Jsp.its 中的数值,它在 Mozilla 中工作正常,但是当我在 IE 中检查它时它不能正常工作。我使用了下面的 Big.js 代码。请查看它并指导我。

我已经使用了这个 Big.jshttp://github.com/whatgoodisaroad/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));
            }
4

1 回答 1

0
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 array
于 2013-08-27T12:14:01.723 回答