-
Notifications
You must be signed in to change notification settings - Fork 2
/
unary_operation_handler.cpp
91 lines (73 loc) · 2.44 KB
/
unary_operation_handler.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// do not try to play with comments
#include "unary_operation_handler.h"
Unary_operation_handler::Unary_operation_handler()
{
}
void Unary_operation_handler::Unary_operation_triggered(QPushButton* button,Ui::MainWindow* ui)
{
double labelnumber;
QString input;
QString symbol;
ui->Error_Label->setText("");
labelnumber = (ui->label->text()).toDouble();
if(button->text() == "+/-")
{
input = QString::number(labelnumber*-1,'g',15);
}
else if(button->text() == "%")
{
input = QString::number(labelnumber*0.01,'g',15);
}
else if(button->text()=="Log"){
if((ui->label->text().toDouble())<=0){
ui->Error_Label->setText("Error message: Log input cant be less then 0");
}
else{
input = QString::number(log10(labelnumber),'g',15);
}
}
else if(button->text() == "√")
{
input = QString::number(sqrt(labelnumber),'g',15);
}
else if(button->text() == "!")
{
input = QString::number(factorial(int(labelnumber)),'g',15);
}
else if(button->text() == "exp"){
input = QString::number(exp(labelnumber),'g',15);
}
else if(button->text() == "sigmoid"){
input = QString::number(1/(1+exp(-labelnumber)),'g',15);
}
else if(button->text() == "sin"){
if(ui->comboBox->currentIndex()==1){input = QString::number(sin(labelnumber/RAD),'g',15);}
else if(ui->comboBox->currentIndex()==2){input = QString::number(cos(labelnumber/GRAD),'g',15);}
else input = QString::number(sin(labelnumber),'g',15);
}
else if(button->text() == "cos"){
if(ui->comboBox->currentIndex()==1){input = QString::number(cos(labelnumber/RAD),'g',15);}
else if(ui->comboBox->currentIndex()==2){input = QString::number(cos(labelnumber/GRAD),'g',15);}
else input = QString::number(cos(labelnumber),'g',15);
}
symbol=button->text();
if(button->text() == "!"){
ui->label_2->setText("(" + QString::number(labelnumber) + ")" +symbol + " = ");
}
else{
ui->label_2->setText(symbol+ "(" + QString::number(labelnumber)+ ")" + " = ");
}
ui->label->setText(input);
}
double Unary_operation_handler::factorial(int labelnumber){
if(labelnumber<=1){
return 1;
}
else if(labelnumber>=FACTORIAL_INFINITY){
return INFINITY;
}
else {
labelnumber-=1;
return (labelnumber+1)*factorial(labelnumber);
}
}