Lines 1855-1866
Link Here
|
1855 |
BYTE nParamCount = GetByte(); |
1855 |
BYTE nParamCount = GetByte(); |
1856 |
if ( !MustHaveParamCountMin( nParamCount, 1 ) ) |
1856 |
if ( !MustHaveParamCountMin( nParamCount, 1 ) ) |
1857 |
return; |
1857 |
return; |
1858 |
USHORT SaveSP = sp; |
|
|
1859 |
USHORT i; |
1858 |
USHORT i; |
1860 |
double fSum = 0.0; |
1859 |
double fSum = 0.0; |
1861 |
double fSumSqr = 0.0; |
1860 |
double vSum = 0.0; |
|
|
1861 |
std::vector<double> values; |
1862 |
double fCount = 0.0; |
1862 |
double fCount = 0.0; |
1863 |
double fVal; |
1863 |
double fVal = 0.0; |
1864 |
ScAddress aAdr; |
1864 |
ScAddress aAdr; |
1865 |
ScRange aRange; |
1865 |
ScRange aRange; |
1866 |
for (i = 0; i < nParamCount; i++) |
1866 |
for (i = 0; i < nParamCount; i++) |
Lines 1871-1877
Link Here
|
1871 |
{ |
1871 |
{ |
1872 |
fVal = GetDouble(); |
1872 |
fVal = GetDouble(); |
1873 |
fSum += fVal; |
1873 |
fSum += fVal; |
1874 |
fSumSqr += fVal*fVal; |
1874 |
values.push_back(fVal); |
1875 |
fCount++; |
1875 |
fCount++; |
1876 |
} |
1876 |
} |
1877 |
break; |
1877 |
break; |
Lines 1883-1889
Link Here
|
1883 |
{ |
1883 |
{ |
1884 |
fVal = GetCellValue( aAdr, pCell ); |
1884 |
fVal = GetCellValue( aAdr, pCell ); |
1885 |
fSum += fVal; |
1885 |
fSum += fVal; |
1886 |
fSumSqr += fVal*fVal; |
1886 |
values.push_back(fVal); |
1887 |
fCount++; |
1887 |
fCount++; |
1888 |
} |
1888 |
} |
1889 |
} |
1889 |
} |
Lines 1896-1908
Link Here
|
1896 |
if (aValIter.GetFirst(fVal, nErr)) |
1896 |
if (aValIter.GetFirst(fVal, nErr)) |
1897 |
{ |
1897 |
{ |
1898 |
fSum += fVal; |
1898 |
fSum += fVal; |
1899 |
fSumSqr += fVal*fVal; |
1899 |
values.push_back(fVal); |
1900 |
fCount++; |
1900 |
fCount++; |
1901 |
SetError(nErr); |
1901 |
SetError(nErr); |
1902 |
while ((nErr == 0) && aValIter.GetNext(fVal, nErr)) |
1902 |
while ((nErr == 0) && aValIter.GetNext(fVal, nErr)) |
1903 |
{ |
1903 |
{ |
1904 |
fSum += fVal; |
1904 |
fSum += fVal; |
1905 |
fSumSqr += fVal*fVal; |
1905 |
values.push_back(fVal); |
1906 |
fCount++; |
1906 |
fCount++; |
1907 |
} |
1907 |
} |
1908 |
SetError(nErr); |
1908 |
SetError(nErr); |
Lines 1921-1927
Link Here
|
1921 |
{ |
1921 |
{ |
1922 |
fVal = pMat->GetDouble(i); |
1922 |
fVal = pMat->GetDouble(i); |
1923 |
fSum += fVal; |
1923 |
fSum += fVal; |
1924 |
fSumSqr += fVal*fVal; |
1924 |
values.push_back(fVal); |
1925 |
fCount++; |
1925 |
fCount++; |
1926 |
} |
1926 |
} |
1927 |
} |
1927 |
} |
Lines 1932-1938
Link Here
|
1932 |
{ |
1932 |
{ |
1933 |
fVal = pMat->GetDouble(i); |
1933 |
fVal = pMat->GetDouble(i); |
1934 |
fSum += fVal; |
1934 |
fSum += fVal; |
1935 |
fSumSqr += fVal*fVal; |
1935 |
values.push_back(fVal); |
1936 |
fCount++; |
1936 |
fCount++; |
1937 |
} |
1937 |
} |
1938 |
} |
1938 |
} |
Lines 1944-2015
Link Here
|
1944 |
break; |
1944 |
break; |
1945 |
} |
1945 |
} |
1946 |
} |
1946 |
} |
|
|
1947 |
|
1947 |
if (nGlobalError) |
1948 |
if (nGlobalError) |
1948 |
{ |
1949 |
{ |
1949 |
PushInt(0); |
1950 |
PushInt(0); |
1950 |
return; |
1951 |
return; |
1951 |
} |
1952 |
} |
|
|
1953 |
|
1952 |
double fMean = fSum / fCount; |
1954 |
double fMean = fSum / fCount; |
1953 |
double fSSqr = (fSumSqr - fSum*fSum/fCount)/(fCount-1.0); |
1955 |
|
1954 |
sp = SaveSP; |
1956 |
for (i = 0; i < values.size(); i++) |
1955 |
fSum = 0.0; |
1957 |
vSum += (values[i] - fMean) * (values[i] - fMean); |
1956 |
// #55733# GCC Optimierungsfehler, GPF wenn die 4.0 als Konstante an pow() |
1958 |
|
1957 |
// uebergeben wird, auch ein "const double fPow = 4.0;" GPF't, |
1959 |
double fStdDev = sqrt(vSum / (fCount - 1.0)); |
1958 |
double fPow = 4.0; |
1960 |
double dx = 0.0; |
1959 |
for (i = 0; i < nParamCount; i++) |
1961 |
double xpower4 = 0.0; |
1960 |
{ |
1962 |
|
1961 |
switch (GetStackType()) |
1963 |
if (fStdDev == 0) |
1962 |
{ |
1964 |
{ |
1963 |
case svDouble : |
1965 |
SetError(errIllegalArgument); |
1964 |
fSum += pow(GetDouble()-fMean,fPow); |
1966 |
return; |
1965 |
break; |
1967 |
} |
1966 |
case svSingleRef : |
1968 |
|
1967 |
{ |
1969 |
for (i = 0; i < values.size(); i++) |
1968 |
PopSingleRef( aAdr ); |
1970 |
{ |
1969 |
ScBaseCell* pCell = GetCell( aAdr ); |
1971 |
dx = (values[i] - fMean) / fStdDev; |
1970 |
if (HasCellValueData(pCell)) |
1972 |
xpower4 = xpower4 + (dx * dx * dx * dx); |
1971 |
fSum += pow(GetCellValue( aAdr, pCell ) - fMean, fPow); |
1973 |
} |
1972 |
} |
1974 |
|
1973 |
break; |
1975 |
double k_d = (fCount - 2.0) * (fCount - 3.0); |
1974 |
case svDoubleRef : |
1976 |
double k_l = fCount * (fCount + 1.0) / ((fCount - 1.0) * k_d); |
1975 |
{ |
1977 |
double k_t = 3.0 * (fCount - 1.0) * (fCount - 1.0) / k_d; |
1976 |
PopDoubleRef( aRange ); |
1978 |
|
1977 |
USHORT nErr = 0; |
1979 |
PushDouble(xpower4 * k_l - k_t); |
1978 |
ScValueIterator aValIter(pDok, aRange); |
|
|
1979 |
if (aValIter.GetFirst(fVal, nErr)) |
1980 |
{ |
1981 |
fSum += pow(fVal - fMean, fPow); |
1982 |
while (aValIter.GetNext(fVal, nErr)) |
1983 |
fSum += pow(fVal - fMean, fPow); |
1984 |
} |
1985 |
} |
1986 |
break; |
1987 |
case svMatrix : |
1988 |
{ |
1989 |
ScMatrix* pMat = PopMatrix(); |
1990 |
if (pMat) |
1991 |
{ |
1992 |
ULONG nCount = pMat->GetElementCount(); |
1993 |
if (pMat->IsNumeric()) |
1994 |
{ |
1995 |
for (ULONG i = 0; i < nCount; i++) |
1996 |
fSum += pow(pMat->GetDouble(i) - fMean, fPow); |
1997 |
} |
1998 |
else |
1999 |
{ |
2000 |
for (ULONG i = 0; i < nCount; i++) |
2001 |
if (!pMat->IsString(i)) |
2002 |
fSum += pow(pMat->GetDouble(i) - fMean, fPow); |
2003 |
} |
2004 |
} |
2005 |
} |
2006 |
break; |
2007 |
default : SetError(errIllegalParameter); break; |
2008 |
} |
2009 |
} |
2010 |
PushDouble(fCount*(fCount+1.0)/((fCount-1.0)*(fCount-2.0)*(fCount-3.0)) |
2011 |
*fSum/(fSSqr*fSSqr) |
2012 |
- 3.0*(fCount-1.0)*(fCount-1.0)/((fCount-2.0)*(fCount-3.0))); |
2013 |
} |
1980 |
} |
2014 |
|
1981 |
|
2015 |
void ScInterpreter::ScHarMean() |
1982 |
void ScInterpreter::ScHarMean() |
Lines 2131-2139
Link Here
|
2131 |
{ |
2098 |
{ |
2132 |
BYTE nParamCount = GetByte(); |
2099 |
BYTE nParamCount = GetByte(); |
2133 |
double nVal = 0.0; |
2100 |
double nVal = 0.0; |
2134 |
ULONG nCount = 0; |
2101 |
double nCount = 0.0; |
2135 |
ScAddress aAdr; |
2102 |
ScAddress aAdr; |
2136 |
ScRange aRange; |
2103 |
ScRange aRange; |
|
|
2104 |
|
2137 |
for (short i = 0; i < nParamCount && (nGlobalError == 0); i++) |
2105 |
for (short i = 0; i < nParamCount && (nGlobalError == 0); i++) |
2138 |
{ |
2106 |
{ |
2139 |
switch (GetStackType()) |
2107 |
switch (GetStackType()) |
Lines 2202-2236
Link Here
|
2202 |
ScMatrix* pMat = PopMatrix(); |
2170 |
ScMatrix* pMat = PopMatrix(); |
2203 |
if (pMat) |
2171 |
if (pMat) |
2204 |
{ |
2172 |
{ |
2205 |
ULONG nCount = pMat->GetElementCount(); |
2173 |
ULONG uCount = pMat->GetElementCount(); |
2206 |
if (pMat->IsNumeric()) |
2174 |
if (pMat->IsNumeric()) |
2207 |
{ |
2175 |
{ |
2208 |
for (ULONG i = 0; i < nCount; i++) |
2176 |
for (ULONG ui = 0; ui < uCount; ui++) |
2209 |
{ |
2177 |
{ |
2210 |
double x = pMat->GetDouble(i); |
2178 |
double x = pMat->GetDouble(ui); |
2211 |
if (x > 0.0) |
2179 |
if (x > 0.0) |
2212 |
{ |
2180 |
{ |
2213 |
nVal += log(x); |
2181 |
nVal += log(x); |
2214 |
nCount++; |
2182 |
nCount++; |
2215 |
} |
2183 |
} |
2216 |
else |
2184 |
else |
2217 |
SetIllegalArgument(); |
2185 |
SetIllegalArgument(); |
2218 |
} |
2186 |
} |
2219 |
} |
2187 |
} |
2220 |
else |
2188 |
else |
2221 |
{ |
2189 |
{ |
2222 |
for (ULONG i = 0; i < nCount; i++) |
2190 |
for (ULONG ui = 0; ui < uCount; ui++) |
2223 |
if (!pMat->IsString(i)) |
2191 |
if (!pMat->IsString(ui)) |
2224 |
{ |
2192 |
{ |
2225 |
double x = pMat->GetDouble(i); |
2193 |
double x = pMat->GetDouble(ui); |
2226 |
if (x > 0.0) |
2194 |
if (x > 0.0) |
2227 |
{ |
2195 |
{ |
2228 |
nVal += log(x); |
2196 |
nVal += log(x); |
2229 |
nCount++; |
2197 |
nCount++; |
2230 |
} |
2198 |
} |
2231 |
else |
2199 |
else |
2232 |
SetIllegalArgument(); |
2200 |
SetIllegalArgument(); |
2233 |
} |
2201 |
} |
2234 |
} |
2202 |
} |
2235 |
} |
2203 |
} |
2236 |
} |
2204 |
} |
Lines 2239-2245
Link Here
|
2239 |
} |
2207 |
} |
2240 |
} |
2208 |
} |
2241 |
if (nGlobalError == 0) |
2209 |
if (nGlobalError == 0) |
2242 |
PushDouble(exp(nVal/(double)nCount)); |
2210 |
PushDouble(exp(nVal / nCount)); |
2243 |
} |
2211 |
} |
2244 |
|
2212 |
|
2245 |
void ScInterpreter::ScStandard() |
2213 |
void ScInterpreter::ScStandard() |
Lines 2261-2272
Link Here
|
2261 |
BYTE nParamCount = GetByte(); |
2229 |
BYTE nParamCount = GetByte(); |
2262 |
if ( !MustHaveParamCountMin( nParamCount, 1 ) ) |
2230 |
if ( !MustHaveParamCountMin( nParamCount, 1 ) ) |
2263 |
return; |
2231 |
return; |
2264 |
USHORT SaveSP = sp; |
|
|
2265 |
USHORT i; |
2232 |
USHORT i; |
2266 |
double fSum = 0.0; |
2233 |
double fSum = 0.0; |
2267 |
double fSumSqr = 0.0; |
2234 |
double vSum = 0.0; |
|
|
2235 |
std::vector<double> values; |
2268 |
double fCount = 0.0; |
2236 |
double fCount = 0.0; |
2269 |
double fVal; |
2237 |
double fVal = 0.0; |
2270 |
ScAddress aAdr; |
2238 |
ScAddress aAdr; |
2271 |
ScRange aRange; |
2239 |
ScRange aRange; |
2272 |
for (i = 0; i < nParamCount; i++) |
2240 |
for (i = 0; i < nParamCount; i++) |
Lines 2277-2283
Link Here
|
2277 |
{ |
2245 |
{ |
2278 |
fVal = GetDouble(); |
2246 |
fVal = GetDouble(); |
2279 |
fSum += fVal; |
2247 |
fSum += fVal; |
2280 |
fSumSqr += fVal*fVal; |
2248 |
values.push_back(fVal); |
2281 |
fCount++; |
2249 |
fCount++; |
2282 |
} |
2250 |
} |
2283 |
break; |
2251 |
break; |
Lines 2289-2295
Link Here
|
2289 |
{ |
2257 |
{ |
2290 |
fVal = GetCellValue( aAdr, pCell ); |
2258 |
fVal = GetCellValue( aAdr, pCell ); |
2291 |
fSum += fVal; |
2259 |
fSum += fVal; |
2292 |
fSumSqr += fVal*fVal; |
2260 |
values.push_back(fVal); |
2293 |
fCount++; |
2261 |
fCount++; |
2294 |
} |
2262 |
} |
2295 |
} |
2263 |
} |
Lines 2302-2314
Link Here
|
2302 |
if (aValIter.GetFirst(fVal, nErr)) |
2270 |
if (aValIter.GetFirst(fVal, nErr)) |
2303 |
{ |
2271 |
{ |
2304 |
fSum += fVal; |
2272 |
fSum += fVal; |
2305 |
fSumSqr += fVal*fVal; |
2273 |
values.push_back(fVal); |
2306 |
fCount++; |
2274 |
fCount++; |
2307 |
SetError(nErr); |
2275 |
SetError(nErr); |
2308 |
while ((nErr == 0) && aValIter.GetNext(fVal, nErr)) |
2276 |
while ((nErr == 0) && aValIter.GetNext(fVal, nErr)) |
2309 |
{ |
2277 |
{ |
2310 |
fSum += fVal; |
2278 |
fSum += fVal; |
2311 |
fSumSqr += fVal*fVal; |
2279 |
values.push_back(fVal); |
2312 |
fCount++; |
2280 |
fCount++; |
2313 |
} |
2281 |
} |
2314 |
SetError(nErr); |
2282 |
SetError(nErr); |
Lines 2327-2333
Link Here
|
2327 |
{ |
2295 |
{ |
2328 |
fVal = pMat->GetDouble(i); |
2296 |
fVal = pMat->GetDouble(i); |
2329 |
fSum += fVal; |
2297 |
fSum += fVal; |
2330 |
fSumSqr += fVal*fVal; |
2298 |
values.push_back(fVal); |
2331 |
fCount++; |
2299 |
fCount++; |
2332 |
} |
2300 |
} |
2333 |
} |
2301 |
} |
Lines 2338-2344
Link Here
|
2338 |
{ |
2306 |
{ |
2339 |
fVal = pMat->GetDouble(i); |
2307 |
fVal = pMat->GetDouble(i); |
2340 |
fSum += fVal; |
2308 |
fSum += fVal; |
2341 |
fSumSqr += fVal*fVal; |
2309 |
values.push_back(fVal); |
2342 |
fCount++; |
2310 |
fCount++; |
2343 |
} |
2311 |
} |
2344 |
} |
2312 |
} |
Lines 2350-2417
Link Here
|
2350 |
break; |
2318 |
break; |
2351 |
} |
2319 |
} |
2352 |
} |
2320 |
} |
|
|
2321 |
|
2353 |
if (nGlobalError) |
2322 |
if (nGlobalError) |
2354 |
{ |
2323 |
{ |
2355 |
PushInt(0); |
2324 |
PushInt(0); |
2356 |
return; |
2325 |
return; |
2357 |
} |
2326 |
} |
|
|
2327 |
|
2358 |
double fMean = fSum / fCount; |
2328 |
double fMean = fSum / fCount; |
2359 |
double fSSqr = (fSumSqr - fSum*fSum/fCount)/(fCount-1.0); |
2329 |
|
2360 |
sp = SaveSP; |
2330 |
for (i = 0; i < values.size(); i++) |
2361 |
fSum = 0.0; |
2331 |
vSum += (values[i] - fMean) * (values[i] - fMean); |
2362 |
double fPow = 3.0; // vorsichtshalber wg. #55733#, siehe ScKurt() |
2332 |
|
2363 |
for (i = 0; i < nParamCount; i++) |
2333 |
double fStdDev = sqrt(vSum / (fCount - 1.0)); |
|
|
2334 |
double dx = 0.0; |
2335 |
double xcube = 0.0; |
2336 |
|
2337 |
if (fStdDev == 0) |
2364 |
{ |
2338 |
{ |
2365 |
switch (GetStackType()) |
2339 |
SetError(errIllegalArgument); |
2366 |
{ |
2340 |
return; |
2367 |
case svDouble : |
2341 |
} |
2368 |
fSum += pow(GetDouble()-fMean,fPow); |
2342 |
|
2369 |
break; |
2343 |
for (i = 0; i < values.size(); i++) |
2370 |
case svSingleRef : |
2344 |
{ |
2371 |
{ |
2345 |
dx = (values[i] - fMean) / fStdDev; |
2372 |
PopSingleRef( aAdr ); |
2346 |
xcube = xcube + (dx * dx * dx); |
2373 |
ScBaseCell* pCell = GetCell( aAdr ); |
|
|
2374 |
if (HasCellValueData(pCell)) |
2375 |
fSum += pow(GetCellValue( aAdr, pCell ) - fMean, fPow); |
2376 |
} |
2377 |
break; |
2378 |
case svDoubleRef : |
2379 |
{ |
2380 |
PopDoubleRef( aRange ); |
2381 |
USHORT nErr = 0; |
2382 |
ScValueIterator aValIter(pDok, aRange); |
2383 |
if (aValIter.GetFirst(fVal, nErr)) |
2384 |
{ |
2385 |
fSum += pow(fVal - fMean, fPow); |
2386 |
while (aValIter.GetNext(fVal, nErr)) |
2387 |
fSum += pow(fVal - fMean, fPow); |
2388 |
} |
2389 |
} |
2390 |
break; |
2391 |
case svMatrix : |
2392 |
{ |
2393 |
ScMatrix* pMat = PopMatrix(); |
2394 |
if (pMat) |
2395 |
{ |
2396 |
ULONG nCount = pMat->GetElementCount(); |
2397 |
if (pMat->IsNumeric()) |
2398 |
{ |
2399 |
for (ULONG i = 0; i < nCount; i++) |
2400 |
fSum += pow(pMat->GetDouble(i) - fMean, fPow); |
2401 |
} |
2402 |
else |
2403 |
{ |
2404 |
for (ULONG i = 0; i < nCount; i++) |
2405 |
if (!pMat->IsString(i)) |
2406 |
fSum += pow(pMat->GetDouble(i) - fMean, fPow); |
2407 |
} |
2408 |
} |
2409 |
} |
2410 |
break; |
2411 |
default : SetError(errIllegalParameter); break; |
2412 |
} |
2413 |
} |
2347 |
} |
2414 |
PushDouble(fCount/((fCount-1.0)*(fCount-2.0))*fSum/(fSSqr*sqrt(fSSqr))); |
2348 |
|
|
|
2349 |
PushDouble(((xcube * fCount) / (fCount - 1.0)) / (fCount - 2.0)); |
2415 |
} |
2350 |
} |
2416 |
|
2351 |
|
2417 |
void ScInterpreter::ScMedian() |
2352 |
void ScInterpreter::ScMedian() |