summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-sheet/sheet.cpp
Unidiff
Diffstat (limited to 'noncore/apps/opie-sheet/sheet.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/opie-sheet/sheet.cpp122
1 files changed, 85 insertions, 37 deletions
diff --git a/noncore/apps/opie-sheet/sheet.cpp b/noncore/apps/opie-sheet/sheet.cpp
index 88847da..477c982 100644
--- a/noncore/apps/opie-sheet/sheet.cpp
+++ b/noncore/apps/opie-sheet/sheet.cpp
@@ -1,23 +1,45 @@
1/*************************************************************************** 1/*
2 * * 2 =. This file is part of the Opie Project
3 * This program is free software; you can redistribute it and/or modify * 3 .=l. Copyright (C) 2004 Opie Developer Team <opie-devel@handhelds.org>
4 * it under the terms of the GNU General Public License as published by * 4 .>+-=
5 * the Free Software Foundation; either version 2 of the License, or * 5 _;:, .> :=|. This program is free software; you can
6 * (at your option) any later version. * 6.> <`_, > . <= redistribute it and/or modify it under
7 * * 7:`=1 )Y*s>-.-- : the terms of the GNU General Public
8 ***************************************************************************/ 8.="- .-=="i, .._ License as published by the Free Software
9 - . .-<_> .<> Foundation; either version 2 of the License,
10 ._= =} : or (at your option) any later version.
11 .%`+i> _;_.
12 .i_,=:_. -<s. This program is distributed in the hope that
13 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
14 : .. .:, . . . without even the implied warranty of
15 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
16 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.= = ; Library General Public License for more
18++= -. .` .: details.
19 : = ...= . :.=-
20 -. .:....=;==+<; You should have received a copy of the GNU
21 -_. . . )=. = Library General Public License along with
22 -- :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
9 28
10/* 29/*
11 * Opie Sheet (formerly Sheet/Qt) 30 * Opie Sheet (formerly Sheet/Qt)
12 * by Serdar Ozler <sozler@sitebest.com> 31 * by Serdar Ozler <sozler@sitebest.com>
13 */ 32 */
14 33
15#include "sheet.h" 34#include "sheet.h"
16 35
36/* QT */
17#include <qmessagebox.h> 37#include <qmessagebox.h>
38
39/* STD */
18#include <math.h> 40#include <math.h>
19#include <stdlib.h> 41#include <stdlib.h>
20#include <stdio.h> 42#include <stdio.h>
21#include <time.h> 43#include <time.h>
22 44
23#define DEFAULT_COL_WIDTH 50 45#define DEFAULT_COL_WIDTH 50
@@ -45,14 +67,13 @@ Sheet::Sheet(int numRows, int numCols, QWidget *parent)
45 67
46 connect(this, SIGNAL(currentChanged(int,int)), this, SLOT(slotCellSelected(int,int))); 68 connect(this, SIGNAL(currentChanged(int,int)), this, SLOT(slotCellSelected(int,int)));
47 connect(this, SIGNAL(valueChanged(int,int)), this, SLOT(slotCellChanged(int,int))); 69 connect(this, SIGNAL(valueChanged(int,int)), this, SLOT(slotCellChanged(int,int)));
48} 70}
49 71
50Sheet::~Sheet() 72Sheet::~Sheet()
51{ 73{}
52}
53 74
54typeCellData *Sheet::findCellData(int row, int col) 75typeCellData *Sheet::findCellData(int row, int col)
55{ 76{
56 typeCellData *tempCellData; 77 typeCellData *tempCellData;
57 for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) 78 for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next())
58 { 79 {
@@ -64,13 +85,14 @@ typeCellData *Sheet::findCellData(int row, int col)
64void Sheet::slotCellSelected(int row, int col) 85void Sheet::slotCellSelected(int row, int col)
65{ 86{
66 typeCellData *cellData=findCellData(row, col); 87 typeCellData *cellData=findCellData(row, col);
67 if (cellData) 88 if (cellData)
68 { 89 {
69 emit currentDataChanged(cellData->data); 90 emit currentDataChanged(cellData->data);
70 }else 91 }
92 else
71 emit currentDataChanged(""); 93 emit currentDataChanged("");
72} 94}
73 95
74typeCellData *Sheet::createCellData(int row, int col) 96typeCellData *Sheet::createCellData(int row, int col)
75{ 97{
76 if (row<0 || col<0) return NULL; 98 if (row<0 || col<0) return NULL;
@@ -225,13 +247,14 @@ double Sheet::BesselI0(double x)
225 double y; 247 double y;
226 if ((ax=fabs(x)) < 3.75) 248 if ((ax=fabs(x)) < 3.75)
227 { 249 {
228 y=x/3.75; 250 y=x/3.75;
229 y*=y; 251 y*=y;
230 ans=1.0+y*(3.5156229+y*(3.0899424+y*(1.2067492 +y*(0.2659732+y*(0.360768e-1+y*0.45813e-2))))); 252 ans=1.0+y*(3.5156229+y*(3.0899424+y*(1.2067492 +y*(0.2659732+y*(0.360768e-1+y*0.45813e-2)))));
231 }else 253 }
254 else
232 { 255 {
233 y=3.75/ax; 256 y=3.75/ax;
234 ans=(exp(ax)/sqrt(ax))*(0.39894228+y*(0.1328592e-1 +y*(0.225319e-2+y*(-0.157565e-2+y*(0.916281e-2 +y*(-0.2057706e-1+y*(0.2635537e-1+y*(-0.1647633e-1 +y*0.392377e-2)))))))); 257 ans=(exp(ax)/sqrt(ax))*(0.39894228+y*(0.1328592e-1 +y*(0.225319e-2+y*(-0.157565e-2+y*(0.916281e-2 +y*(-0.2057706e-1+y*(0.2635537e-1+y*(-0.1647633e-1 +y*0.392377e-2))))))));
235 } 258 }
236 return ans; 259 return ans;
237}; 260};
@@ -242,13 +265,14 @@ double Sheet::BesselI1(double x)
242 double y; 265 double y;
243 if ((ax=fabs(x)) < 3.75) 266 if ((ax=fabs(x)) < 3.75)
244 { 267 {
245 y=x/3.75; 268 y=x/3.75;
246 y*=y; 269 y*=y;
247 ans=ax*(0.5+y*(0.87890594+y*(0.51498869+y*(0.15084934 +y*(0.2658733e-1+y*(0.301532e-2+y*0.32411e-3)))))); 270 ans=ax*(0.5+y*(0.87890594+y*(0.51498869+y*(0.15084934 +y*(0.2658733e-1+y*(0.301532e-2+y*0.32411e-3))))));
248 } else 271 }
272 else
249 { 273 {
250 y=3.75/ax; 274 y=3.75/ax;
251 ans=0.2282967e-1+y*(-0.2895312e-1+y*(0.1787654e-1 -y*0.420059e-2)); ans=0.39894228+y*(-0.3988024e-1+y*(-0.362018e-2 +y*(0.163801e-2+y*(-0.1031555e-1+y*ans)))); 275 ans=0.2282967e-1+y*(-0.2895312e-1+y*(0.1787654e-1 -y*0.420059e-2)); ans=0.39894228+y*(-0.3988024e-1+y*(-0.362018e-2 +y*(0.163801e-2+y*(-0.1031555e-1+y*ans))));
252 ans *= (exp(ax)/sqrt(ax)); 276 ans *= (exp(ax)/sqrt(ax));
253 } 277 }
254 return x < 0.0 ? -ans : ans; 278 return x < 0.0 ? -ans : ans;
@@ -289,13 +313,14 @@ double Sheet::BesselK0(double x)
289{ 313{
290 double y,ans; 314 double y,ans;
291 if (x <= 2.0) 315 if (x <= 2.0)
292 { 316 {
293 y=x*x/4.0; 317 y=x*x/4.0;
294 ans=(-log(x/2.0)*BesselI0(x))+(-0.57721566+y*(0.42278420 +y*(0.23069756+y*(0.3488590e-1+y*(0.262698e-2 +y*(0.10750e-3+y*0.74e-5)))))); 318 ans=(-log(x/2.0)*BesselI0(x))+(-0.57721566+y*(0.42278420 +y*(0.23069756+y*(0.3488590e-1+y*(0.262698e-2 +y*(0.10750e-3+y*0.74e-5))))));
295 } else 319 }
320 else
296 { 321 {
297 y=2.0/x; 322 y=2.0/x;
298 ans=(exp(-x)/sqrt(x))*(1.25331414+y*(-0.7832358e-1 +y*(0.2189568e-1+y*(-0.1062446e-1+y*(0.587872e-2 +y*(-0.251540e-2+y*0.53208e-3)))))); 323 ans=(exp(-x)/sqrt(x))*(1.25331414+y*(-0.7832358e-1 +y*(0.2189568e-1+y*(-0.1062446e-1+y*(0.587872e-2 +y*(-0.251540e-2+y*0.53208e-3))))));
299 } 324 }
300return ans; 325return ans;
301}; 326};
@@ -304,13 +329,14 @@ double Sheet::BesselK1(double x)
304{ 329{
305 double y,ans; 330 double y,ans;
306 if (x <= 2.0) 331 if (x <= 2.0)
307 { 332 {
308 y=x*x/4.0; 333 y=x*x/4.0;
309 ans=(log(x/2.0)*BesselI1(x))+(1.0/x)*(1.0+y*(0.15443144 +y*(-0.67278579+y*(-0.18156897+y*(-0.1919402e-1 +y*(-0.110404e-2+y*(-0.4686e-4))))))); 334 ans=(log(x/2.0)*BesselI1(x))+(1.0/x)*(1.0+y*(0.15443144 +y*(-0.67278579+y*(-0.18156897+y*(-0.1919402e-1 +y*(-0.110404e-2+y*(-0.4686e-4)))))));
310 } else 335 }
336 else
311 { 337 {
312 y=2.0/x; 338 y=2.0/x;
313 ans=(exp(-x)/sqrt(x))*(1.25331414+y*(0.23498619 +y*(-0.3655620e-1+y*(0.1504268e-1+y*(-0.780353e-2 +y*(0.325614e-2+y*(-0.68245e-3))))))); 339 ans=(exp(-x)/sqrt(x))*(1.25331414+y*(0.23498619 +y*(-0.3655620e-1+y*(0.1504268e-1+y*(-0.780353e-2 +y*(0.325614e-2+y*(-0.68245e-3)))))));
314 } 340 }
315 return ans; 341 return ans;
316}; 342};
@@ -339,13 +365,14 @@ double Sheet::BesselJ0(double x)
339 if ((ax=fabs(x)) < 8.0) 365 if ((ax=fabs(x)) < 8.0)
340 { 366 {
341 y=x*x; 367 y=x*x;
342 ans1=57568490574.0+y*(-13362590354.0+y*(651619640.7 +y*(-11214424.18+y*(77392.33017+y*(-184.9052456))))); 368 ans1=57568490574.0+y*(-13362590354.0+y*(651619640.7 +y*(-11214424.18+y*(77392.33017+y*(-184.9052456)))));
343 ans2=57568490411.0+y*(1029532985.0+y*(9494680.718 +y*(59272.64853+y*(267.8532712+y*1.0)))); 369 ans2=57568490411.0+y*(1029532985.0+y*(9494680.718 +y*(59272.64853+y*(267.8532712+y*1.0))));
344 ans=ans1/ans2; 370 ans=ans1/ans2;
345 } else 371 }
372 else
346 { 373 {
347 z=8.0/ax; 374 z=8.0/ax;
348 y=z*z; 375 y=z*z;
349 xx=ax-0.785398164; 376 xx=ax-0.785398164;
350 ans1=1.0+y*(-0.1098628627e-2+y*(0.2734510407e-4 +y*(-0.2073370639e-5+y*0.2093887211e-6))); 377 ans1=1.0+y*(-0.1098628627e-2+y*(0.2734510407e-4 +y*(-0.2073370639e-5+y*0.2093887211e-6)));
351 ans2 = -0.1562499995e-1+y*(0.1430488765e-3 +y*(-0.6911147651e-5+y*(0.7621095161e-6 -y*0.934935152e-7))); 378 ans2 = -0.1562499995e-1+y*(0.1430488765e-3 +y*(-0.6911147651e-5+y*(0.7621095161e-6 -y*0.934935152e-7)));
@@ -361,13 +388,14 @@ double Sheet::BesselY0(double x)
361 if (x < 8.0) 388 if (x < 8.0)
362 { 389 {
363 y=x*x; 390 y=x*x;
364 ans1 = -2957821389.0+y*(7062834065.0+y*(-512359803.6 +y*(10879881.29+y*(-86327.92757+y*228.4622733)))); 391 ans1 = -2957821389.0+y*(7062834065.0+y*(-512359803.6 +y*(10879881.29+y*(-86327.92757+y*228.4622733))));
365 ans2=40076544269.0+y*(745249964.8+y*(7189466.438 +y*(47447.26470+y*(226.1030244+y*1.0)))); 392 ans2=40076544269.0+y*(745249964.8+y*(7189466.438 +y*(47447.26470+y*(226.1030244+y*1.0))));
366 ans=(ans1/ans2)+0.636619772*BesselJ0(x)*log(x); 393 ans=(ans1/ans2)+0.636619772*BesselJ0(x)*log(x);
367 } else 394 }
395 else
368 { 396 {
369 z=8.0/x; 397 z=8.0/x;
370 y=z*z; 398 y=z*z;
371 xx=x-0.785398164; 399 xx=x-0.785398164;
372 ans1=1.0+y*(-0.1098628627e-2+y*(0.2734510407e-4 +y*(-0.2073370639e-5+y*0.2093887211e-6))); 400 ans1=1.0+y*(-0.1098628627e-2+y*(0.2734510407e-4 +y*(-0.2073370639e-5+y*0.2093887211e-6)));
373 ans2 = -0.1562499995e-1+y*(0.1430488765e-3 +y*(-0.6911147651e-5+y*(0.7621095161e-6 +y*(-0.934945152e-7)))); 401 ans2 = -0.1562499995e-1+y*(0.1430488765e-3 +y*(-0.6911147651e-5+y*(0.7621095161e-6 +y*(-0.934945152e-7))));
@@ -383,13 +411,14 @@ double Sheet::BesselJ1(double x)
383 if ((ax=fabs(x)) < 8.0) 411 if ((ax=fabs(x)) < 8.0)
384 { 412 {
385 y=x*x; 413 y=x*x;
386 ans1=x*(72362614232.0+y*(-7895059235.0+y*(242396853.1 +y*(-2972611.439+y*(15704.48260+y*(-30.16036606)))))); 414 ans1=x*(72362614232.0+y*(-7895059235.0+y*(242396853.1 +y*(-2972611.439+y*(15704.48260+y*(-30.16036606))))));
387 ans2=144725228442.0+y*(2300535178.0+y*(18583304.74 +y*(99447.43394+y*(376.9991397+y*1.0)))); 415 ans2=144725228442.0+y*(2300535178.0+y*(18583304.74 +y*(99447.43394+y*(376.9991397+y*1.0))));
388 ans=ans1/ans2; 416 ans=ans1/ans2;
389 } else 417 }
418 else
390 { 419 {
391 z=8.0/ax; y=z*z; xx=ax-2.356194491; 420 z=8.0/ax; y=z*z; xx=ax-2.356194491;
392 ans1=1.0+y*(0.183105e-2+y*(-0.3516396496e-4 +y*(0.2457520174e-5+y*(-0.240337019e-6)))); 421 ans1=1.0+y*(0.183105e-2+y*(-0.3516396496e-4 +y*(0.2457520174e-5+y*(-0.240337019e-6))));
393 ans2=0.04687499995+y*(-0.2002690873e-3 +y*(0.8449199096e-5+y*(-0.88228987e-6 +y*0.105787412e-6))); 422 ans2=0.04687499995+y*(-0.2002690873e-3 +y*(0.8449199096e-5+y*(-0.88228987e-6 +y*0.105787412e-6)));
394 ans=sqrt(0.636619772/ax)*(cos(xx)*ans1-z*sin(xx)*ans2); 423 ans=sqrt(0.636619772/ax)*(cos(xx)*ans1-z*sin(xx)*ans2);
395 if (x < 0.0) ans = -ans; 424 if (x < 0.0) ans = -ans;
@@ -404,13 +433,14 @@ double Sheet::BesselY1(double x)
404 if (x < 8.0) 433 if (x < 8.0)
405 { 434 {
406 y=x*x; 435 y=x*x;
407 ans1=x*(-0.4900604943e13+y*(0.1275274390e13 +y*(-0.5153438139e11+y*(0.7349264551e9 +y*(-0.4237922726e7+y*0.8511937935e4))))); 436 ans1=x*(-0.4900604943e13+y*(0.1275274390e13 +y*(-0.5153438139e11+y*(0.7349264551e9 +y*(-0.4237922726e7+y*0.8511937935e4)))));
408 ans2=0.2499580570e14+y*(0.4244419664e12 +y*(0.3733650367e10+y*(0.2245904002e8 +y*(0.1020426050e6+y*(0.3549632885e3+y))))); 437 ans2=0.2499580570e14+y*(0.4244419664e12 +y*(0.3733650367e10+y*(0.2245904002e8 +y*(0.1020426050e6+y*(0.3549632885e3+y)))));
409 ans=(ans1/ans2)+0.636619772*(BesselJ1(x)*log(x)-1.0/x); 438 ans=(ans1/ans2)+0.636619772*(BesselJ1(x)*log(x)-1.0/x);
410 } else 439 }
440 else
411 { 441 {
412 z=8.0/x; 442 z=8.0/x;
413 y=z*z; 443 y=z*z;
414 xx=x-2.356194491; 444 xx=x-2.356194491;
415 ans1=1.0+y*(0.183105e-2+y*(-0.3516396496e-4 +y*(0.2457520174e-5+y*(-0.240337019e-6)))); 445 ans1=1.0+y*(0.183105e-2+y*(-0.3516396496e-4 +y*(0.2457520174e-5+y*(-0.240337019e-6))));
416 ans2=0.04687499995+y*(-0.2002690873e-3 +y*(0.8449199096e-5+y*(-0.88228987e-6 +y*0.105787412e-6))); 446 ans2=0.04687499995+y*(-0.2002690873e-3 +y*(0.8449199096e-5+y*(-0.88228987e-6 +y*0.105787412e-6)));
@@ -455,13 +485,14 @@ double Sheet::BesselJ(int n, double x)
455 { 485 {
456 bjp=j*tox*bj-bjm; 486 bjp=j*tox*bj-bjm;
457 bjm=bj; 487 bjm=bj;
458 bj=bjp; 488 bj=bjp;
459 } 489 }
460 ans=bj; 490 ans=bj;
461 } else 491 }
492 else
462 { 493 {
463 tox=2.0/ax; 494 tox=2.0/ax;
464 m=2*((n+(int) sqrt(ACC*n))/2); 495 m=2*((n+(int) sqrt(ACC*n))/2);
465 jsum=0; 496 jsum=0;
466 bjp=ans=sum=0.0; 497 bjp=ans=sum=0.0;
467 bj=1.0; 498 bj=1.0;
@@ -515,13 +546,14 @@ double Sheet::GammaP(double a, double x)
515 double gamser,gammcf,gln; 546 double gamser,gammcf,gln;
516 if (x < 0.0 || a <= 0.0) return 0.0;//error 547 if (x < 0.0 || a <= 0.0) return 0.0;//error
517 if (x < (a+1.0)) 548 if (x < (a+1.0))
518 { 549 {
519 GammaSeries(&gamser,a,x,&gln); 550 GammaSeries(&gamser,a,x,&gln);
520 return gamser; 551 return gamser;
521 }else 552 }
553 else
522 { 554 {
523 GammaContinuedFraction(&gammcf,a,x,&gln); 555 GammaContinuedFraction(&gammcf,a,x,&gln);
524 return 1.0-gammcf; 556 return 1.0-gammcf;
525 } 557 }
526}; 558};
527 559
@@ -541,13 +573,14 @@ void Sheet::GammaSeries(double *gamser, double a, double x, double *gln)
541 *gln=GammaLn(a); 573 *gln=GammaLn(a);
542 if (x <= 0.0) 574 if (x <= 0.0)
543 { 575 {
544 if (x < 0.0) return;//error 576 if (x < 0.0) return;//error
545 *gamser=0.0; 577 *gamser=0.0;
546 return; 578 return;
547 } else 579 }
580 else
548 { 581 {
549 ap=a; 582 ap=a;
550 del=sum=1.0/a; 583 del=sum=1.0/a;
551 for (n=1;n<=ITMAX;n++) 584 for (n=1;n<=ITMAX;n++)
552 { 585 {
553 ++ap; 586 ++ap;
@@ -555,13 +588,14 @@ void Sheet::GammaSeries(double *gamser, double a, double x, double *gln)
555 sum += del; 588 sum += del;
556 if (fabs(del) < fabs(sum)*EPS) 589 if (fabs(del) < fabs(sum)*EPS)
557 { 590 {
558 *gamser=sum*exp(-x+a*log(x)-(*gln)); 591 *gamser=sum*exp(-x+a*log(x)-(*gln));
559 return; 592 return;
560 } 593 }
561 } return; 594 }
595 return;
562 return; 596 return;
563 } 597 }
564}; 598};
565 599
566 600
567void Sheet::GammaContinuedFraction(double *gammcf, double a, double x, double *gln) 601void Sheet::GammaContinuedFraction(double *gammcf, double a, double x, double *gln)
@@ -659,13 +693,14 @@ double Sheet::functionSum(const QString &param1, const QString &param2)
659 for (col=col1; col<=col2; ++col) 693 for (col=col1; col<=col2; ++col)
660 { 694 {
661 tempResult=text(row, col).toDouble(&ok); 695 tempResult=text(row, col).toDouble(&ok);
662 if (ok) result+=tempResult; 696 if (ok) result+=tempResult;
663 } 697 }
664 return result; 698 return result;
665 }else 699 }
700 else
666 { 701 {
667 double d1=0,d2=0; 702 double d1=0,d2=0;
668 d1=calculateVariable(param1).toDouble(&ok); 703 d1=calculateVariable(param1).toDouble(&ok);
669 d2=calculateVariable(param2).toDouble(&ok); 704 d2=calculateVariable(param2).toDouble(&ok);
670 return(d1+d2); 705 return(d1+d2);
671 }; 706 };
@@ -786,13 +821,14 @@ double Sheet::functionSumSQ(const QString &param1, const QString &param2)
786 for (col=col1; col<=col2; ++col) 821 for (col=col1; col<=col2; ++col)
787 { 822 {
788 tempResult=text(row, col).toDouble(&ok); 823 tempResult=text(row, col).toDouble(&ok);
789 if (ok) result+=tempResult*tempResult; 824 if (ok) result+=tempResult*tempResult;
790 } 825 }
791 return result; 826 return result;
792 }else 827 }
828 else
793 { 829 {
794 double d1=0,d2=0; 830 double d1=0,d2=0;
795 d1=calculateVariable(param1).toDouble(&ok); 831 d1=calculateVariable(param1).toDouble(&ok);
796 d2=calculateVariable(param2).toDouble(&ok); 832 d2=calculateVariable(param2).toDouble(&ok);
797 return(d1*d1+d2*d2); 833 return(d1*d1+d2*d2);
798 }; 834 };
@@ -816,13 +852,14 @@ double Sheet::functionMin(const QString &param1, const QString &param2)
816 { 852 {
817 min=tempMin; 853 min=tempMin;
818 init=TRUE; 854 init=TRUE;
819 } 855 }
820 } 856 }
821 return min; 857 return min;
822 }else 858 }
859 else
823 { 860 {
824 double d1=0,d2=0; 861 double d1=0,d2=0;
825 d1=calculateVariable(param1).toDouble(&ok); 862 d1=calculateVariable(param1).toDouble(&ok);
826 d2=calculateVariable(param2).toDouble(&ok); 863 d2=calculateVariable(param2).toDouble(&ok);
827 if(d1<d2) return(d1); else return(d2); 864 if(d1<d2) return(d1); else return(d2);
828 }; 865 };
@@ -844,13 +881,14 @@ double Sheet::functionMax(const QString &param1, const QString &param2)
844 { 881 {
845 max=tempMax; 882 max=tempMax;
846 init=TRUE; 883 init=TRUE;
847 } 884 }
848 }; 885 };
849 return max; 886 return max;
850 }else 887 }
888 else
851 { 889 {
852 double d1=0,d2=0; 890 double d1=0,d2=0;
853 d1=calculateVariable(param1).toDouble(&ok); 891 d1=calculateVariable(param1).toDouble(&ok);
854 d2=calculateVariable(param2).toDouble(&ok); 892 d2=calculateVariable(param2).toDouble(&ok);
855 if(d1>d2) return(d1); else return(d2); 893 if(d1>d2) return(d1); else return(d2);
856 }; 894 };
@@ -874,13 +912,14 @@ double Sheet::functionCount(const QString &param1, const QString &param2)
874 for (col=col1; col<=col2; ++col) 912 for (col=col1; col<=col2; ++col)
875 { 913 {
876 text(row, col).toDouble(&ok); 914 text(row, col).toDouble(&ok);
877 if (ok) ++divider; 915 if (ok) ++divider;
878 }; 916 };
879 return divider; 917 return divider;
880 }else 918 }
919 else
881 { 920 {
882 double d1=0,d2=0;int ii=0; 921 double d1=0,d2=0;int ii=0;
883 d1=calculateVariable(param1).toDouble(&ok); 922 d1=calculateVariable(param1).toDouble(&ok);
884 if (ok) ii++; 923 if (ok) ii++;
885 d2=calculateVariable(param2).toDouble(&ok); 924 d2=calculateVariable(param2).toDouble(&ok);
886 if (ok) ii++; 925 if (ok) ii++;
@@ -989,18 +1028,20 @@ QString Sheet::calculateFunction(const QString &func, const QString &parameters,
989 //LOGICAL / INFO 1028 //LOGICAL / INFO
990 if (function=="ISBLANK") 1029 if (function=="ISBLANK")
991 { 1030 {
992 if(findRowColumn(getParameter(parameters, 0), &row, &col, FALSE)) 1031 if(findRowColumn(getParameter(parameters, 0), &row, &col, FALSE))
993 { 1032 {
994 if(text(row,col).length()==0) val1=1; else val1=0; 1033 if(text(row,col).length()==0) val1=1; else val1=0;
995 }else 1034 }
1035 else
996 { 1036 {
997 if(findRowColumn(calculateVariable(getParameter(parameters, 0)), &row,&col, FALSE)) 1037 if(findRowColumn(calculateVariable(getParameter(parameters, 0)), &row,&col, FALSE))
998 { 1038 {
999 if(text(row,col).length()==0) val1=1; else val1=0; 1039 if(text(row,col).length()==0) val1=1; else val1=0;
1000 }else 1040 }
1041 else
1001 { 1042 {
1002 val1=0; 1043 val1=0;
1003 }; 1044 };
1004 }; 1045 };
1005 return QString::number(val1); 1046 return QString::number(val1);
1006 }; 1047 };
@@ -1009,19 +1050,21 @@ QString Sheet::calculateFunction(const QString &func, const QString &parameters,
1009 if (function=="ISNUMBER") 1050 if (function=="ISNUMBER")
1010 { 1051 {
1011 if(findRowColumn(getParameter(parameters, 0, TRUE, function), &row, &col, FALSE)) 1052 if(findRowColumn(getParameter(parameters, 0, TRUE, function), &row, &col, FALSE))
1012 { 1053 {
1013 val1=text(row,col).toDouble(&ok); 1054 val1=text(row,col).toDouble(&ok);
1014 if(ok) val1=1; else val1=0; 1055 if(ok) val1=1; else val1=0;
1015 }else 1056 }
1057 else
1016 { 1058 {
1017 if(findRowColumn(calculateVariable(getParameter(parameters, 0, TRUE, function)), &row,&col, FALSE)) 1059 if(findRowColumn(calculateVariable(getParameter(parameters, 0, TRUE, function)), &row,&col, FALSE))
1018 { 1060 {
1019 val1=text(row,col).toDouble(&ok); 1061 val1=text(row,col).toDouble(&ok);
1020 if(ok) val1=1; else val1=0; 1062 if(ok) val1=1; else val1=0;
1021 }else 1063 }
1064 else
1022 { 1065 {
1023 val1=0; 1066 val1=0;
1024 }; 1067 };
1025 }; 1068 };
1026 return QString::number(val1); 1069 return QString::number(val1);
1027 }; 1070 };
@@ -1386,13 +1429,14 @@ QString Sheet::calculateFunction(const QString &func, const QString &parameters,
1386 //returns param4 if true(param1)/ param5 if false(param1) 1429 //returns param4 if true(param1)/ param5 if false(param1)
1387 val1=getParameter(parameters, 0, TRUE, function).toDouble(&ok); 1430 val1=getParameter(parameters, 0, TRUE, function).toDouble(&ok);
1388 if(val1==1.0) 1431 if(val1==1.0)
1389 { 1432 {
1390 s1=calculateVariable(getParameter(parameters, 1, TRUE, function)); 1433 s1=calculateVariable(getParameter(parameters, 1, TRUE, function));
1391 return QString(s1); 1434 return QString(s1);
1392 }else 1435 }
1436 else
1393 { 1437 {
1394 s1=calculateVariable(getParameter(parameters, 2, TRUE, function)); 1438 s1=calculateVariable(getParameter(parameters, 2, TRUE, function));
1395 return QString(s1); 1439 return QString(s1);
1396 }; 1440 };
1397 }; 1441 };
1398 if (function=="SUM") 1442 if (function=="SUM")
@@ -1549,13 +1593,14 @@ QString Sheet::calculateFunction(const QString &func, const QString &parameters,
1549 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1593 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1550 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); 1594 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok);
1551 vali=calculateVariable(getParameter(parameters, 2, TRUE, function)).toInt(&ok); 1595 vali=calculateVariable(getParameter(parameters, 2, TRUE, function)).toInt(&ok);
1552 if(vali==1) 1596 if(vali==1)
1553 { 1597 {
1554 return QString::number(GammaQ(floor(val1)+1, val2)); 1598 return QString::number(GammaQ(floor(val1)+1, val2));
1555 }else 1599 }
1600 else
1556 { 1601 {
1557 return QString::number(exp(-val2)*pow(val2,val1)/exp(GammaLn(val1+1.0))); 1602 return QString::number(exp(-val2)*pow(val2,val1)/exp(GammaLn(val1+1.0)));
1558 }; 1603 };
1559 }; 1604 };
1560 if(function=="CHIDIST") 1605 if(function=="CHIDIST")
1561 { 1606 {
@@ -1563,13 +1608,14 @@ QString Sheet::calculateFunction(const QString &func, const QString &parameters,
1563 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1608 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1564 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); 1609 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok);
1565 vali=calculateVariable(getParameter(parameters, 2, TRUE, function)).toInt(&ok); 1610 vali=calculateVariable(getParameter(parameters, 2, TRUE, function)).toInt(&ok);
1566 if(vali==1) 1611 if(vali==1)
1567 { 1612 {
1568 return QString::number(GammaP(val2/2.0,val1*val1/2.0)); 1613 return QString::number(GammaP(val2/2.0,val1*val1/2.0));
1569 } else 1614 }
1615 else
1570 { 1616 {
1571 return QString::number( 1617 return QString::number(
1572 pow(val1,val2-1.0)*exp(-val1*val1/2)/ ( pow(2,val2/2.0-1.0)*exp(GammaLn(val2/2.0))) 1618 pow(val1,val2-1.0)*exp(-val1*val1/2)/ ( pow(2,val2/2.0-1.0)*exp(GammaLn(val2/2.0)))
1573 ); 1619 );
1574 }; 1620 };
1575 }; 1621 };
@@ -1579,13 +1625,14 @@ QString Sheet::calculateFunction(const QString &func, const QString &parameters,
1579 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1625 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1580 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); 1626 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok);
1581 vali=calculateVariable(getParameter(parameters, 2, TRUE, function)).toInt(&ok); 1627 vali=calculateVariable(getParameter(parameters, 2, TRUE, function)).toInt(&ok);
1582 if(vali==1) 1628 if(vali==1)
1583 { 1629 {
1584 return QString::number(GammaP(val2/2.0,val1/2.0)); 1630 return QString::number(GammaP(val2/2.0,val1/2.0));
1585 } else 1631 }
1632 else
1586 { 1633 {
1587 return QString::number( 1634 return QString::number(
1588 pow(val1,val2/2.0-1.0)/(exp(val1/2.0)*pow(sqrt(2.0),val2)*exp(GammaLn(val2/2.0))) 1635 pow(val1,val2/2.0-1.0)/(exp(val1/2.0)*pow(sqrt(2.0),val2)*exp(GammaLn(val2/2.0)))
1589 ); 1636 );
1590 }; 1637 };
1591 }; 1638 };
@@ -2382,13 +2429,14 @@ void Expression::GetNext()
2382 else 2429 else
2383 { 2430 {
2384 break; 2431 break;
2385 } 2432 }
2386 }//while 2433 }//while
2387 }//else if 2434 }//else if
2388};//end function 2435}
2436;//end function
2389 2437
2390 2438
2391void Expression::First() 2439void Expression::First()
2392{ 2440{
2393 GetNext(); 2441 GetNext();
2394 if (!(chunk=="") && !ErrorFound) Third(); 2442 if (!(chunk=="") && !ErrorFound) Third();