diff -up yuan/interpr1.cxx xiugai/interpr1.cxx --- yuan/interpr1.cxx 2007-12-10 14:59:32.000000000 +0800 +++ xiugai/interpr1.cxx 2008-01-07 16:53:22.000000000 +0800 @@ -2764,7 +2764,7 @@ void ScInterpreter::ScAsc() void ScInterpreter::ScMin( BOOL bTextAsZero ) { BYTE nParamCount = GetByte(); - double nMin = SC_DOUBLE_MAXVALUE; + double nMin = ::std::numeric_limits::max(); double nVal = 0.0; ScAddress aAdr; ScRange aRange; @@ -2801,18 +2801,21 @@ void ScInterpreter::ScMin( BOOL bTextAsZ USHORT nErr = 0; PopDoubleRef( aRange ); ScValueIterator aValIter( pDok, aRange, glSubTotal, bTextAsZero ); - if (aValIter.GetFirst(nVal, nErr)) - { - if (nMin > nVal) - nMin = nVal; - aValIter.GetCurNumFmtInfo( nFuncFmtType, nFuncFmtIndex ); - while ((nErr == 0) && aValIter.GetNext(nVal, nErr)) - { - if (nMin > nVal) - nMin = nVal; - } - SetError(nErr); - } + double nTmpVal = 0.0; + if (aValIter.GetFirst(nTmpVal, nErr)) + { + nVal = nTmpVal; + if (nMin > nVal) + nMin = nVal; + aValIter.GetCurNumFmtInfo( nFuncFmtType, nFuncFmtIndex ); + while ((nErr == 0) && aValIter.GetNext(nTmpVal, nErr)) + { + nVal = nTmpVal; + if (nMin > nVal) + nMin = nVal; + } + SetError(nErr); + } } break; case svMatrix : @@ -2871,9 +2874,11 @@ void ScInterpreter::ScMin( BOOL bTextAsZ SetError(errIllegalParameter); } } - if (nMin == SC_DOUBLE_MAXVALUE) - SetIllegalArgument(); - else + if ( 0 == nParamCount ) + SetIllegalArgument(); + else if ( nVal < nMin ) + PushDouble(0.0); + else PushDouble(nMin); } @@ -2884,7 +2889,7 @@ void ScInterpreter::ScMin( BOOL bTextAsZ void ScInterpreter::ScMax( BOOL bTextAsZero ) { BYTE nParamCount = GetByte(); - double nMax = -SC_DOUBLE_MAXVALUE; + double nMax = -(::std::numeric_limits::max()); double nVal = 0.0; ScAddress aAdr; ScRange aRange; @@ -2921,13 +2926,16 @@ void ScInterpreter::ScMax( BOOL bTextAsZ USHORT nErr = 0; PopDoubleRef( aRange ); ScValueIterator aValIter( pDok, aRange, glSubTotal, bTextAsZero ); - if (aValIter.GetFirst(nVal, nErr)) + double nTmpVal = 0.0; + if (aValIter.GetFirst(nTmpVal, nErr)) { + nVal = nTmpVal; if (nMax < nVal) nMax = nVal; aValIter.GetCurNumFmtInfo( nFuncFmtType, nFuncFmtIndex ); - while ((nErr == 0) && aValIter.GetNext(nVal, nErr)) + while ((nErr == 0) && aValIter.GetNext(nTmpVal, nErr)) { + nVal = nTmpVal; if (nMax < nVal) nMax = nVal; } @@ -2991,8 +2999,10 @@ void ScInterpreter::ScMax( BOOL bTextAsZ SetError(errIllegalParameter); } } - if (nMax == -SC_DOUBLE_MAXVALUE) - SetIllegalArgument(); + if ( 0 == nParamCount ) + SetIllegalArgument(); + else if ( nVal > nMax ) + PushDouble(0.0); else PushDouble(nMax); }