diff -up old/interpr5.cxx new/interpr5.cxx --- old/interpr5.cxx 2008-01-16 22:30:22.000000000 +0800 +++ new/interpr5.cxx 2008-01-22 14:17:16.000000000 +0800 @@ -72,8 +72,10 @@ double ScInterpreter::ScGetGGT(double fx { if (fy == 0.0 || fx == 0.0) { - SetError(errIllegalArgument); - return 1.0; + if ( fy == 0.0 ) + return fx; + else + return fy; } else { @@ -93,7 +95,6 @@ void ScInterpreter::ScGGT() BYTE nParamCount = GetByte(); if ( MustHaveParamCountMin( nParamCount, 1 ) ) { - double fSign = 1.0; double fx, fy = 0.0; switch (GetStackType()) { @@ -101,11 +102,11 @@ void ScInterpreter::ScGGT() case svString: case svSingleRef: { - fy = GetDouble(); + fy = ::rtl::math::approxFloor( GetDouble() ); if (fy < 0.0) { - fy *= -1.0; - fSign *= -1.0; + SetIllegalArgument(); + return; } } break; @@ -118,19 +119,19 @@ void ScInterpreter::ScGGT() ScValueIterator aValIter(pDok, aRange, glSubTotal); if (aValIter.GetFirst(nCellVal, nErr)) { - fy = nCellVal; + fy = ::rtl::math::approxFloor( nCellVal ); if (fy < 0.0) { - fy *= -1.0; - fSign *= -1.0; + SetIllegalArgument(); + return; } while (nErr == 0 && aValIter.GetNext(nCellVal, nErr)) { - fx = nCellVal; + fx = ::rtl::math::approxFloor( nCellVal ); if (fx < 0.0) { - fx *= -1.0; - fSign *= -1.0; + SetIllegalArgument(); + return; } fy = ScGetGGT(fx, fy); } @@ -156,11 +157,11 @@ void ScInterpreter::ScGGT() SetIllegalArgument(); return; } - fy = pMat->GetDouble(0); + fy = ::rtl::math::approxFloor( pMat->GetDouble(0) ); if (fy < 0.0) { - fy *= -1.0; - fSign *= -1.0; + SetIllegalArgument(); + return; } SCSIZE nCount = nC * nR; for ( SCSIZE j = 1; j < nCount; j++ ) @@ -170,11 +171,11 @@ void ScInterpreter::ScGGT() SetIllegalArgument(); return; } - fx = pMat->GetDouble(j); + fx = ::rtl::math::approxFloor( pMat->GetDouble(j) ); if (fx < 0.0) { - fx *= -1.0; - fSign *= -1.0; + SetIllegalArgument(); + return; } fy = ScGetGGT(fx, fy); } @@ -193,11 +194,11 @@ void ScInterpreter::ScGGT() case svString: case svSingleRef: { - fx = GetDouble(); + fx = ::rtl::math::approxFloor( GetDouble() ); if (fx < 0.0) { - fx *= -1.0; - fSign *= -1.0; + SetIllegalArgument(); + return; } fy = ScGetGGT(fx, fy); } @@ -210,20 +211,20 @@ void ScInterpreter::ScGGT() ScValueIterator aValIter(pDok, aRange, glSubTotal); if (aValIter.GetFirst(nCellVal, nErr)) { - fx = nCellVal; + fx = ::rtl::math::approxFloor( nCellVal ); if (fx < 0.0) { - fx *= -1.0; - fSign *= -1.0; + SetIllegalArgument(); + return; } fy = ScGetGGT(fx, fy); while (nErr == 0 && aValIter.GetNext(nCellVal, nErr)) { - fx = nCellVal; + fx = ::rtl::math::approxFloor( nCellVal ); if (fx < 0.0) { - fx *= -1.0; - fSign *= -1.0; + SetIllegalArgument(); + return; } fy = ScGetGGT(fx, fy); } @@ -249,11 +250,11 @@ void ScInterpreter::ScGGT() SetIllegalArgument(); return; } - fx = pMat->GetDouble(0); + fx = ::rtl::math::approxFloor( pMat->GetDouble(0) ); if (fx < 0.0) { - fx *= -1.0; - fSign *= -1.0; + SetIllegalArgument(); + return; } fy = ScGetGGT(fx, fy); SCSIZE nCount = nC * nR; @@ -264,11 +265,11 @@ void ScInterpreter::ScGGT() SetIllegalArgument(); return; } - fx = pMat->GetDouble(j); + fx = ::rtl::math::approxFloor( pMat->GetDouble(j) ); if (fx < 0.0) { - fx *= -1.0; - fSign *= -1.0; + SetIllegalArgument(); + return; } fy = ScGetGGT(fx, fy); } @@ -279,10 +280,7 @@ void ScInterpreter::ScGGT() default : SetError(errIllegalParameter); break; } } - if (fSign == -1.0) - PushDouble(-fy); - else - PushDouble(fy); + PushDouble(fy); } } @@ -291,7 +289,6 @@ void ScInterpreter:: ScKGV() BYTE nParamCount = GetByte(); if ( MustHaveParamCountMin( nParamCount, 1 ) ) { - double fSign = 1.0; double fx, fy = 0.0; switch (GetStackType()) { @@ -299,11 +296,11 @@ void ScInterpreter:: ScKGV() case svString: case svSingleRef: { - fy = GetDouble(); + fy = ::rtl::math::approxFloor( GetDouble() ); if (fy < 0.0) { - fy *= -1.0; - fSign *= -1.0; + SetIllegalArgument(); + return; } } break; @@ -316,21 +313,24 @@ void ScInterpreter:: ScKGV() ScValueIterator aValIter(pDok, aRange, glSubTotal); if (aValIter.GetFirst(nCellVal, nErr)) { - fy = nCellVal; + fy = ::rtl::math::approxFloor( nCellVal ); if (fy < 0.0) { - fy *= -1.0; - fSign *= -1.0; + SetIllegalArgument(); + return; } while (nErr == 0 && aValIter.GetNext(nCellVal, nErr)) { - fx = nCellVal; + fx = ::rtl::math::approxFloor( nCellVal ); if (fx < 0.0) { - fx *= -1.0; - fSign *= -1.0; + SetIllegalArgument(); + return; } - fy = fx * fy / ScGetGGT(fx, fy); + if ( fy == 0.0 || fx == 0.0 ) + fy = 0.0; + else + fy = fx * fy / ScGetGGT(fx, fy); } SetError(nErr); } @@ -354,11 +354,11 @@ void ScInterpreter:: ScKGV() SetIllegalArgument(); return; } - fy = pMat->GetDouble(0); + fy = ::rtl::math::approxFloor( pMat->GetDouble(0) ); if (fy < 0.0) { - fy *= -1.0; - fSign *= -1.0; + SetIllegalArgument(); + return; } SCSIZE nCount = nC * nR; for ( SCSIZE j = 1; j < nCount; j++ ) @@ -368,13 +368,16 @@ void ScInterpreter:: ScKGV() SetIllegalArgument(); return; } - fx = pMat->GetDouble(j); + fx = ::rtl::math::approxFloor( pMat->GetDouble(j) ); if (fx < 0.0) { - fx *= -1.0; - fSign *= -1.0; + SetIllegalArgument(); + return; } - fy = fx * fy / ScGetGGT(fx, fy); + if ( fy == 0.0 || fx == 0.0 ) + fy = 0.0; + else + fy = fx * fy / ScGetGGT(fx, fy); } } } @@ -391,13 +394,16 @@ void ScInterpreter:: ScKGV() case svString: case svSingleRef: { - fx = GetDouble(); + fx = ::rtl::math::approxFloor( GetDouble() ); if (fx < 0.0) { - fx *= -1.0; - fSign *= -1.0; + SetIllegalArgument(); + return; } - fy = fx * fy / ScGetGGT(fx, fy); + if ( fy == 0.0 || fx == 0.0 ) + fy = 0.0; + else + fy = fx * fy / ScGetGGT(fx, fy); } break; case svDoubleRef : @@ -408,22 +414,28 @@ void ScInterpreter:: ScKGV() ScValueIterator aValIter(pDok, aRange, glSubTotal); if (aValIter.GetFirst(nCellVal, nErr)) { - fx = nCellVal; + fx = ::rtl::math::approxFloor( nCellVal ); if (fx < 0.0) { - fx *= -1.0; - fSign *= -1.0; + SetIllegalArgument(); + return; } - fy = fx * fy / ScGetGGT(fx, fy); + if ( fy == 0.0 || fx == 0.0 ) + fy = 0.0; + else + fy = fx * fy / ScGetGGT(fx, fy); while (nErr == 0 && aValIter.GetNext(nCellVal, nErr)) { - fx = nCellVal; + fx = ::rtl::math::approxFloor( nCellVal ); if (fx < 0.0) { - fx *= -1.0; - fSign *= -1.0; + SetIllegalArgument(); + return; } - fy = fx * fy / ScGetGGT(fx, fy); + if ( fy == 0.0 || fx == 0.0 ) + fy = 0.0; + else + fy = fx * fy / ScGetGGT(fx, fy); } SetError(nErr); } @@ -447,13 +459,16 @@ void ScInterpreter:: ScKGV() SetIllegalArgument(); return; } - fx = pMat->GetDouble(0); + fx = ::rtl::math::approxFloor( pMat->GetDouble(0) ); if (fx < 0.0) { - fx *= -1.0; - fSign *= -1.0; + SetIllegalArgument(); + return; } - fy = fx * fy / ScGetGGT(fx, fy); + if ( fy == 0.0 || fx == 0.0 ) + fy = 0.0; + else + fy = fx * fy / ScGetGGT(fx, fy); SCSIZE nCount = nC * nR; for ( SCSIZE j = 1; j < nCount; j++ ) { @@ -462,13 +477,16 @@ void ScInterpreter:: ScKGV() SetIllegalArgument(); return; } - fx = pMat->GetDouble(j); + fx = ::rtl::math::approxFloor( pMat->GetDouble(j) ); if (fx < 0.0) { - fx *= -1.0; - fSign *= -1.0; + SetIllegalArgument(); + return; } - fy = fx * fy / ScGetGGT(fx, fy); + if ( fy == 0.0 || fx == 0.0 ) + fy = 0.0; + else + fy = fx * fy / ScGetGGT(fx, fy); } } } @@ -477,10 +495,7 @@ void ScInterpreter:: ScKGV() default : SetError(errIllegalParameter); break; } } - if (fSign == -1.0) - PushDouble(-fy); - else - PushDouble(fy); + PushDouble(fy); } }