aboutsummaryrefslogtreecommitdiff
path: root/src-qt5/desktop-utils/lumina-calculator/mainUI.cpp
diff options
context:
space:
mode:
authorKen Moore <ken@ixsystems.com>2016-10-20 13:35:45 -0400
committerKen Moore <ken@ixsystems.com>2016-10-20 13:35:45 -0400
commit79cfa16f8e6923762221e70180518636d73f5018 (patch)
treed93c8c10fb8d7964aadc0c45841359a9590ae8a3 /src-qt5/desktop-utils/lumina-calculator/mainUI.cpp
parentHook up the Lumina theme engine into lumina-calculator for icon changes, as w... (diff)
downloadlumina-79cfa16f8e6923762221e70180518636d73f5018.tar.gz
lumina-79cfa16f8e6923762221e70180518636d73f5018.tar.bz2
lumina-79cfa16f8e6923762221e70180518636d73f5018.zip
Fix up the parsing/usage of scientific notation within the equation (1e1 or 1E1 = 10)
Similarly, skip any +/- at the beginning of a number/section with no context for operation purposes (is a modifier for the number, not an actual operation)
Diffstat (limited to 'src-qt5/desktop-utils/lumina-calculator/mainUI.cpp')
-rw-r--r--src-qt5/desktop-utils/lumina-calculator/mainUI.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/src-qt5/desktop-utils/lumina-calculator/mainUI.cpp b/src-qt5/desktop-utils/lumina-calculator/mainUI.cpp
index 3db2e028..baaa0a27 100644
--- a/src-qt5/desktop-utils/lumina-calculator/mainUI.cpp
+++ b/src-qt5/desktop-utils/lumina-calculator/mainUI.cpp
@@ -81,6 +81,7 @@ void mainUI::captureButtonMultiply(){ ui->line_eq->setText(ui->line_eq->text() +
void mainUI::captureButtonDecimal(){ ui->line_eq->setText(ui->line_eq->text() += ui->button_Decimal->text()); }
double mainUI::performOperation(double LHS, double RHS, QChar symbol){
+ qDebug() << "Perform Operation:" << LHS << symbol << RHS;
if(symbol== '+'){ return (LHS+RHS); }
else if(symbol== '-'){ return (LHS-RHS); }
else if(symbol== '*' || symbol=='x'){ return (LHS*RHS); }
@@ -92,7 +93,7 @@ double mainUI::performOperation(double LHS, double RHS, QChar symbol){
double mainUI::strToNumber(QString str){
//Look for perentheses first
- //qDebug() << "String to Number: " << str;
+ qDebug() << "String to Number: " << str;
if(str.indexOf("(")>=0){
//qDebug() << "Found Parenthesis";
int start = str.indexOf("(");
@@ -116,9 +117,14 @@ double mainUI::strToNumber(QString str){
//Now look for add/subtract
int sym = -1;
QStringList symbols; symbols << "+" << "-";
+ qDebug() << "Get operator:" << str;
for(int i=0; i<symbols.length(); i++){
int tmp = str.indexOf(symbols[i]);
- if(sym < tmp){ sym = tmp; }
+ while(tmp==0 || (tmp>0 && str[tmp-1].toLower()=='e') ){ tmp = str.indexOf(symbols[i], tmp+1); } //catch scientific notation
+ if(sym < tmp){
+ //qDebug() << " - found:" << tmp << sym;
+ sym = tmp;
+ }
}
if(sym>0){ return performOperation( strToNumber(str.left(sym)), strToNumber(str.right(str.length()-sym-1)), str[sym]); }
if(sym==0){ return BADVALUE; }
@@ -132,6 +138,6 @@ double mainUI::strToNumber(QString str){
if(sym==0){ return BADVALUE; }
//Could not find any operations - must be a raw number
- //qDebug() << "Found Number:" << str.toDouble();
+ qDebug() << " - Found Number:" << str << str.toDouble();
return str.toDouble();
}
bgstack15