/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. *
*/
for (; i + 3 < nUnrolledSize; i += 4)
{
sum0 += *pCurrent++;
sum1 += *pCurrent++;
sum2 += *pCurrent++;
sum3 += *pCurrent++;
} // We are using pairwise summation alongside Kahan return (sum0 + sum1) + (sum2 + sum3);
} return 0.0;
}
/** * This function task is to choose the fastest method available to perform the sum. * @param i * @param nSize * @param pCurrent
*/ staticinline KahanSum executeFast(size_t& i, size_t nSize, constdouble* pCurrent)
{ #if SC_USE_SSE2 return executeSSE2(i, nSize, pCurrent); #else return executeUnrolled(i, nSize, pCurrent); #endif
}
/** * Performs the sum of an array. * Note that align 16 will speed up the process. * @param pArray * @param nSize
*/ inline KahanSum sumArray(constdouble* pArray, size_t nSize)
{
size_t i = 0; constdouble* pCurrent = pArray;
KahanSum fSum = executeFast(i, nSize, pCurrent);
// sum rest of the array for (; i < nSize; ++i)
fSum += pArray[i];
// If the sum is a NaN, some of the terms were empty cells, probably. // Re-calculate, carefully double fVal = fSum.get(); if (!std::isfinite(fVal))
{
FormulaError nErr = GetDoubleErrorValue(fVal); if (nErr == FormulaError::NoValue)
{
fSum = 0; for (i = 0; i < nSize; i++)
{ if (!std::isfinite(pArray[i]))
{
nErr = GetDoubleErrorValue(pArray[i]); if (nErr != FormulaError::NoValue)
fSum += pArray[i]; // Let errors encoded as NaNs propagate ???
} else
fSum += pArray[i];
}
}
} return fSum;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.