summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-sheet/sheet.cpp
Side-by-side diff
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,21 +1,43 @@
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- ***************************************************************************/
+/*
+ =. This file is part of the Opie Project
+ .=l. Copyright (C) 2004 Opie Developer Team <opie-devel@handhelds.org>
+ .>+-=
+ _;:, .> :=|. This program is free software; you can
+.> <`_, > . <= redistribute it and/or modify it under
+:`=1 )Y*s>-.-- : the terms of the GNU General Public
+.="- .-=="i, .._ License as published by the Free Software
+ - . .-<_> .<> Foundation; either version 2 of the License,
+ ._= =} : or (at your option) any later version.
+ .%`+i> _;_.
+ .i_,=:_. -<s. This program is distributed in the hope that
+ + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
+ : .. .:, . . . without even the implied warranty of
+ =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
+ _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
+..}^=.= = ; Library General Public License for more
+++= -. .` .: details.
+ : = ...= . :.=-
+ -. .:....=;==+<; You should have received a copy of the GNU
+ -_. . . )=. = Library General Public License along with
+ -- :-=` this library; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
/*
* Opie Sheet (formerly Sheet/Qt)
* by Serdar Ozler <sozler@sitebest.com>
*/
#include "sheet.h"
+/* QT */
#include <qmessagebox.h>
+
+/* STD */
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
@@ -47,10 +69,9 @@ Sheet::Sheet(int numRows, int numCols, QWidget *parent)
connect(this, SIGNAL(valueChanged(int,int)), this, SLOT(slotCellChanged(int,int)));
}
Sheet::~Sheet()
-{
-}
+{}
typeCellData *Sheet::findCellData(int row, int col)
{
typeCellData *tempCellData;
@@ -66,9 +87,10 @@ void Sheet::slotCellSelected(int row, int col)
typeCellData *cellData=findCellData(row, col);
if (cellData)
{
emit currentDataChanged(cellData->data);
- }else
+ }
+ else
emit currentDataChanged("");
}
typeCellData *Sheet::createCellData(int row, int col)
@@ -227,9 +249,10 @@ double Sheet::BesselI0(double x)
{
y=x/3.75;
y*=y;
ans=1.0+y*(3.5156229+y*(3.0899424+y*(1.2067492 +y*(0.2659732+y*(0.360768e-1+y*0.45813e-2)))));
- }else
+ }
+ else
{
y=3.75/ax;
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))))))));
}
@@ -244,9 +267,10 @@ double Sheet::BesselI1(double x)
{
y=x/3.75;
y*=y;
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))))));
- } else
+ }
+ else
{
y=3.75/ax;
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))));
ans *= (exp(ax)/sqrt(ax));
@@ -291,9 +315,10 @@ double Sheet::BesselK0(double x)
if (x <= 2.0)
{
y=x*x/4.0;
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))))));
- } else
+ }
+ else
{
y=2.0/x;
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))))));
}
@@ -306,9 +331,10 @@ double Sheet::BesselK1(double x)
if (x <= 2.0)
{
y=x*x/4.0;
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)))))));
- } else
+ }
+ else
{
y=2.0/x;
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)))))));
}
@@ -341,9 +367,10 @@ double Sheet::BesselJ0(double x)
y=x*x;
ans1=57568490574.0+y*(-13362590354.0+y*(651619640.7 +y*(-11214424.18+y*(77392.33017+y*(-184.9052456)))));
ans2=57568490411.0+y*(1029532985.0+y*(9494680.718 +y*(59272.64853+y*(267.8532712+y*1.0))));
ans=ans1/ans2;
- } else
+ }
+ else
{
z=8.0/ax;
y=z*z;
xx=ax-0.785398164;
@@ -363,9 +390,10 @@ double Sheet::BesselY0(double x)
y=x*x;
ans1 = -2957821389.0+y*(7062834065.0+y*(-512359803.6 +y*(10879881.29+y*(-86327.92757+y*228.4622733))));
ans2=40076544269.0+y*(745249964.8+y*(7189466.438 +y*(47447.26470+y*(226.1030244+y*1.0))));
ans=(ans1/ans2)+0.636619772*BesselJ0(x)*log(x);
- } else
+ }
+ else
{
z=8.0/x;
y=z*z;
xx=x-0.785398164;
@@ -385,9 +413,10 @@ double Sheet::BesselJ1(double x)
y=x*x;
ans1=x*(72362614232.0+y*(-7895059235.0+y*(242396853.1 +y*(-2972611.439+y*(15704.48260+y*(-30.16036606))))));
ans2=144725228442.0+y*(2300535178.0+y*(18583304.74 +y*(99447.43394+y*(376.9991397+y*1.0))));
ans=ans1/ans2;
- } else
+ }
+ else
{
z=8.0/ax; y=z*z; xx=ax-2.356194491;
ans1=1.0+y*(0.183105e-2+y*(-0.3516396496e-4 +y*(0.2457520174e-5+y*(-0.240337019e-6))));
ans2=0.04687499995+y*(-0.2002690873e-3 +y*(0.8449199096e-5+y*(-0.88228987e-6 +y*0.105787412e-6)));
@@ -406,9 +435,10 @@ double Sheet::BesselY1(double x)
y=x*x;
ans1=x*(-0.4900604943e13+y*(0.1275274390e13 +y*(-0.5153438139e11+y*(0.7349264551e9 +y*(-0.4237922726e7+y*0.8511937935e4)))));
ans2=0.2499580570e14+y*(0.4244419664e12 +y*(0.3733650367e10+y*(0.2245904002e8 +y*(0.1020426050e6+y*(0.3549632885e3+y)))));
ans=(ans1/ans2)+0.636619772*(BesselJ1(x)*log(x)-1.0/x);
- } else
+ }
+ else
{
z=8.0/x;
y=z*z;
xx=x-2.356194491;
@@ -457,9 +487,10 @@ double Sheet::BesselJ(int n, double x)
bjm=bj;
bj=bjp;
}
ans=bj;
- } else
+ }
+ else
{
tox=2.0/ax;
m=2*((n+(int) sqrt(ACC*n))/2);
jsum=0;
@@ -517,9 +548,10 @@ double Sheet::GammaP(double a, double x)
if (x < (a+1.0))
{
GammaSeries(&gamser,a,x,&gln);
return gamser;
- }else
+ }
+ else
{
GammaContinuedFraction(&gammcf,a,x,&gln);
return 1.0-gammcf;
}
@@ -543,9 +575,10 @@ void Sheet::GammaSeries(double *gamser, double a, double x, double *gln)
{
if (x < 0.0) return;//error
*gamser=0.0;
return;
- } else
+ }
+ else
{
ap=a;
del=sum=1.0/a;
for (n=1;n<=ITMAX;n++)
@@ -557,9 +590,10 @@ void Sheet::GammaSeries(double *gamser, double a, double x, double *gln)
{
*gamser=sum*exp(-x+a*log(x)-(*gln));
return;
}
- } return;
+ }
+ return;
return;
}
};
@@ -661,9 +695,10 @@ double Sheet::functionSum(const QString &param1, const QString &param2)
tempResult=text(row, col).toDouble(&ok);
if (ok) result+=tempResult;
}
return result;
- }else
+ }
+ else
{
double d1=0,d2=0;
d1=calculateVariable(param1).toDouble(&ok);
d2=calculateVariable(param2).toDouble(&ok);
@@ -788,9 +823,10 @@ double Sheet::functionSumSQ(const QString &param1, const QString &param2)
tempResult=text(row, col).toDouble(&ok);
if (ok) result+=tempResult*tempResult;
}
return result;
- }else
+ }
+ else
{
double d1=0,d2=0;
d1=calculateVariable(param1).toDouble(&ok);
d2=calculateVariable(param2).toDouble(&ok);
@@ -818,9 +854,10 @@ double Sheet::functionMin(const QString &param1, const QString &param2)
init=TRUE;
}
}
return min;
- }else
+ }
+ else
{
double d1=0,d2=0;
d1=calculateVariable(param1).toDouble(&ok);
d2=calculateVariable(param2).toDouble(&ok);
@@ -846,9 +883,10 @@ double Sheet::functionMax(const QString &param1, const QString &param2)
init=TRUE;
}
};
return max;
- }else
+ }
+ else
{
double d1=0,d2=0;
d1=calculateVariable(param1).toDouble(&ok);
d2=calculateVariable(param2).toDouble(&ok);
@@ -876,9 +914,10 @@ double Sheet::functionCount(const QString &param1, const QString &param2)
text(row, col).toDouble(&ok);
if (ok) ++divider;
};
return divider;
- }else
+ }
+ else
{
double d1=0,d2=0;int ii=0;
d1=calculateVariable(param1).toDouble(&ok);
if (ok) ii++;
@@ -991,14 +1030,16 @@ QString Sheet::calculateFunction(const QString &func, const QString &parameters,
{
if(findRowColumn(getParameter(parameters, 0), &row, &col, FALSE))
{
if(text(row,col).length()==0) val1=1; else val1=0;
- }else
+ }
+ else
{
if(findRowColumn(calculateVariable(getParameter(parameters, 0)), &row,&col, FALSE))
{
if(text(row,col).length()==0) val1=1; else val1=0;
- }else
+ }
+ else
{
val1=0;
};
};
@@ -1011,15 +1052,17 @@ QString Sheet::calculateFunction(const QString &func, const QString &parameters,
if(findRowColumn(getParameter(parameters, 0, TRUE, function), &row, &col, FALSE))
{
val1=text(row,col).toDouble(&ok);
if(ok) val1=1; else val1=0;
- }else
+ }
+ else
{
if(findRowColumn(calculateVariable(getParameter(parameters, 0, TRUE, function)), &row,&col, FALSE))
{
val1=text(row,col).toDouble(&ok);
if(ok) val1=1; else val1=0;
- }else
+ }
+ else
{
val1=0;
};
};
@@ -1388,9 +1431,10 @@ QString Sheet::calculateFunction(const QString &func, const QString &parameters,
if(val1==1.0)
{
s1=calculateVariable(getParameter(parameters, 1, TRUE, function));
return QString(s1);
- }else
+ }
+ else
{
s1=calculateVariable(getParameter(parameters, 2, TRUE, function));
return QString(s1);
};
@@ -1551,9 +1595,10 @@ QString Sheet::calculateFunction(const QString &func, const QString &parameters,
vali=calculateVariable(getParameter(parameters, 2, TRUE, function)).toInt(&ok);
if(vali==1)
{
return QString::number(GammaQ(floor(val1)+1, val2));
- }else
+ }
+ else
{
return QString::number(exp(-val2)*pow(val2,val1)/exp(GammaLn(val1+1.0)));
};
};
@@ -1565,9 +1610,10 @@ QString Sheet::calculateFunction(const QString &func, const QString &parameters,
vali=calculateVariable(getParameter(parameters, 2, TRUE, function)).toInt(&ok);
if(vali==1)
{
return QString::number(GammaP(val2/2.0,val1*val1/2.0));
- } else
+ }
+ else
{
return QString::number(
pow(val1,val2-1.0)*exp(-val1*val1/2)/ ( pow(2,val2/2.0-1.0)*exp(GammaLn(val2/2.0)))
);
@@ -1581,9 +1627,10 @@ QString Sheet::calculateFunction(const QString &func, const QString &parameters,
vali=calculateVariable(getParameter(parameters, 2, TRUE, function)).toInt(&ok);
if(vali==1)
{
return QString::number(GammaP(val2/2.0,val1/2.0));
- } else
+ }
+ else
{
return QString::number(
pow(val1,val2/2.0-1.0)/(exp(val1/2.0)*pow(sqrt(2.0),val2)*exp(GammaLn(val2/2.0)))
);
@@ -2384,9 +2431,10 @@ void Expression::GetNext()
break;
}
}//while
}//else if
-};//end function
+}
+;//end function
void Expression::First()
{