diff options
author | Michael Stahl <mst@openoffice.org> | 2010-08-27 12:21:15 +0200 |
---|---|---|
committer | Michael Stahl <mst@openoffice.org> | 2010-08-27 12:21:15 +0200 |
commit | 66d630adfe176550381534fc56450e9041004744 (patch) | |
tree | e123fe369cc0ff24f33eac2832241adc7e6c2b0d | |
parent | 5ccdcb471976d739a43597b47660d5254a137f6f (diff) |
dba33h: #i112652#: math.cxx: indent stuff a bit and clean up whitespace
-rw-r--r-- | sal/rtl/source/math.cxx | 265 |
1 files changed, 135 insertions, 130 deletions
diff --git a/sal/rtl/source/math.cxx b/sal/rtl/source/math.cxx index a6c2bd389..83f34aa6a 100644 --- a/sal/rtl/source/math.cxx +++ b/sal/rtl/source/math.cxx @@ -1,7 +1,7 @@ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * + * * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite @@ -737,157 +737,162 @@ inline double stringToDouble(CharT const * pBegin, CharT const * pEnd, } CharT const * p = p0; - // leading zeros and group separators may be safely ignored - while (p != pEnd && (*p == CharT('0') || *p == cGroupSeparator)) - ++p; - - long nValExp = 0; // carry along exponent of mantissa - - // integer part of mantissa - for (; p != pEnd; ++p) - { - CharT c = *p; - if (isDigit(c)) - { - fVal = fVal * 10.0 + static_cast< double >( c - CharT('0') ); - ++nValExp; - } - else if (c != cGroupSeparator) - break; - } - - // fraction part of mantissa - if (p != pEnd && *p == cDecSeparator) { - ++p; - double fFrac = 0.0; - long nFracExp = 0; - while (p != pEnd && *p == CharT('0')) - { - --nFracExp; + // leading zeros and group separators may be safely ignored + while (p != pEnd && (*p == CharT('0') || *p == cGroupSeparator)) ++p; - } - if ( nValExp == 0 ) - nValExp = nFracExp - 1; // no integer part => fraction exponent - // one decimal digit needs ld(10) ~= 3.32 bits - static const int nSigs = (DBL_MANT_DIG / 3) + 1; - int nDigs = 0; + + long nValExp = 0; // carry along exponent of mantissa + + // integer part of mantissa for (; p != pEnd; ++p) { CharT c = *p; - if (!isDigit(c)) - break; - if ( nDigs < nSigs ) - { // further digits (more than nSigs) don't have any significance - fFrac = fFrac * 10.0 + static_cast< double >( c - CharT('0') ); - --nFracExp; - ++nDigs; + if (isDigit(c)) + { + fVal = fVal * 10.0 + static_cast< double >( c - CharT('0') ); + ++nValExp; } + else if (c != cGroupSeparator) + break; } - if ( fFrac != 0.0 ) - fVal += rtl::math::pow10Exp( fFrac, nFracExp ); - else if ( nValExp < 0 ) - nValExp = 0; // no digit other than 0 after decimal point - } - - if ( nValExp > 0 ) - --nValExp; // started with offset +1 at the first mantissa digit - // Exponent - if (p != p0 && p != pEnd && (*p == CharT('E') || *p == CharT('e'))) - { - ++p; - bool bExpSign; - if (p != pEnd && *p == CharT('-')) + // fraction part of mantissa + if (p != pEnd && *p == cDecSeparator) { - bExpSign = true; ++p; - } - else - { - bExpSign = false; - if (p != pEnd && *p == CharT('+')) - ++p; - } - if ( fVal == 0.0 ) - { // no matter what follows, zero stays zero, but carry on the offset - while (p != pEnd && isDigit(*p)) + double fFrac = 0.0; + long nFracExp = 0; + while (p != pEnd && *p == CharT('0')) + { + --nFracExp; ++p; - } - else - { - bool bOverFlow = false; - long nExp = 0; + } + if ( nValExp == 0 ) + nValExp = nFracExp - 1; // no integer part => fraction exponent + // one decimal digit needs ld(10) ~= 3.32 bits + static const int nSigs = (DBL_MANT_DIG / 3) + 1; + int nDigs = 0; for (; p != pEnd; ++p) { CharT c = *p; if (!isDigit(c)) break; - int i = c - CharT('0'); - if ( long10Overflow( nExp, i ) ) - bOverFlow = true; - else - nExp = nExp * 10 + i; - } - if ( nExp ) - { - if ( bExpSign ) - nExp = -nExp; - long nAllExp = ( bOverFlow ? 0 : nExp + nValExp ); - if ( nAllExp > DBL_MAX_10_EXP || (bOverFlow && !bExpSign) ) - { // overflow - fVal = HUGE_VAL; - eStatus = rtl_math_ConversionStatus_OutOfRange; - } - else if ( nAllExp < DBL_MIN_10_EXP || (bOverFlow && bExpSign) ) - { // underflow - fVal = 0.0; - eStatus = rtl_math_ConversionStatus_OutOfRange; + if ( nDigs < nSigs ) + { // further digits (more than nSigs) don't have any + // significance + fFrac = fFrac * 10.0 + static_cast<double>(c - CharT('0')); + --nFracExp; + ++nDigs; } - else if ( nExp > DBL_MAX_10_EXP || nExp < DBL_MIN_10_EXP ) - { // compensate exponents - fVal = rtl::math::pow10Exp( fVal, -nValExp ); - fVal = rtl::math::pow10Exp( fVal, nAllExp ); - } - else - fVal = rtl::math::pow10Exp( fVal, nExp ); // normal } + if ( fFrac != 0.0 ) + fVal += rtl::math::pow10Exp( fFrac, nFracExp ); + else if ( nValExp < 0 ) + nValExp = 0; // no digit other than 0 after decimal point } - } - else if (p - p0 == 2 && p != pEnd && p[0] == CharT('#') - && p[-1] == cDecSeparator && p[-2] == CharT('1')) - { - if (pEnd - p >= 4 && p[1] == CharT('I') && p[2] == CharT('N') - && p[3] == CharT('F')) + + if ( nValExp > 0 ) + --nValExp; // started with offset +1 at the first mantissa digit + + // Exponent + if (p != p0 && p != pEnd && (*p == CharT('E') || *p == CharT('e'))) { - // "1.#INF", "+1.#INF", "-1.#INF" - p += 4; - fVal = HUGE_VAL; - eStatus = rtl_math_ConversionStatus_OutOfRange; - // Eat any further digits: - while (p != pEnd && isDigit(*p)) + ++p; + bool bExpSign; + if (p != pEnd && *p == CharT('-')) + { + bExpSign = true; ++p; + } + else + { + bExpSign = false; + if (p != pEnd && *p == CharT('+')) + ++p; + } + if ( fVal == 0.0 ) + { // no matter what follows, zero stays zero, but carry on the + // offset + while (p != pEnd && isDigit(*p)) + ++p; + } + else + { + bool bOverFlow = false; + long nExp = 0; + for (; p != pEnd; ++p) + { + CharT c = *p; + if (!isDigit(c)) + break; + int i = c - CharT('0'); + if ( long10Overflow( nExp, i ) ) + bOverFlow = true; + else + nExp = nExp * 10 + i; + } + if ( nExp ) + { + if ( bExpSign ) + nExp = -nExp; + long nAllExp = ( bOverFlow ? 0 : nExp + nValExp ); + if ( nAllExp > DBL_MAX_10_EXP || (bOverFlow && !bExpSign) ) + { // overflow + fVal = HUGE_VAL; + eStatus = rtl_math_ConversionStatus_OutOfRange; + } + else if ((nAllExp < DBL_MIN_10_EXP) || + (bOverFlow && bExpSign) ) + { // underflow + fVal = 0.0; + eStatus = rtl_math_ConversionStatus_OutOfRange; + } + else if ( nExp > DBL_MAX_10_EXP || nExp < DBL_MIN_10_EXP ) + { // compensate exponents + fVal = rtl::math::pow10Exp( fVal, -nValExp ); + fVal = rtl::math::pow10Exp( fVal, nAllExp ); + } + else + fVal = rtl::math::pow10Exp( fVal, nExp ); // normal + } + } } - else if (pEnd - p >= 4 && p[1] == CharT('N') && p[2] == CharT('A') - && p[3] == CharT('N')) + else if (p - p0 == 2 && p != pEnd && p[0] == CharT('#') + && p[-1] == cDecSeparator && p[-2] == CharT('1')) { - // "1.#NAN", "+1.#NAN", "-1.#NAN" - p += 4; - rtl::math::setNan( &fVal ); - if (bSign) + if (pEnd - p >= 4 && p[1] == CharT('I') && p[2] == CharT('N') + && p[3] == CharT('F')) { - union { - double sd; - sal_math_Double md; - } m; - m.sd = fVal; - m.md.w32_parts.msw |= 0x80000000; // create negative NaN - fVal = m.sd; - bSign = false; // don't negate again + // "1.#INF", "+1.#INF", "-1.#INF" + p += 4; + fVal = HUGE_VAL; + eStatus = rtl_math_ConversionStatus_OutOfRange; + // Eat any further digits: + while (p != pEnd && isDigit(*p)) + ++p; + } + else if (pEnd - p >= 4 && p[1] == CharT('N') && p[2] == CharT('A') + && p[3] == CharT('N')) + { + // "1.#NAN", "+1.#NAN", "-1.#NAN" + p += 4; + rtl::math::setNan( &fVal ); + if (bSign) + { + union { + double sd; + sal_math_Double md; + } m; + m.sd = fVal; + m.md.w32_parts.msw |= 0x80000000; // create negative NaN + fVal = m.sd; + bSign = false; // don't negate again + } + // Eat any further digits: + while (p != pEnd && isDigit(*p)) + ++p; } - // Eat any further digits: - while (p != pEnd && isDigit(*p)) - ++p; } } @@ -1100,9 +1105,9 @@ double SAL_CALL rtl_math_expm1( double fValue ) SAL_THROW_EXTERN_C() double SAL_CALL rtl_math_log1p( double fValue ) SAL_THROW_EXTERN_C() { - // Use volatile because a compiler may be too smart "optimizing" the - // condition such that in certain cases the else path was called even if - // (fp==1.0) was true, where the term (fp-1.0) then resulted in 0.0 and + // Use volatile because a compiler may be too smart "optimizing" the + // condition such that in certain cases the else path was called even if + // (fp==1.0) was true, where the term (fp-1.0) then resulted in 0.0 and // hence the entire expression resulted in NaN. // Happened with g++ 3.4.1 and an input value of 9.87E-18 volatile double fp = 1.0 + fValue; |