summaryrefslogtreecommitdiff
path: root/noncore/tools/calc2/main
Unidiff
Diffstat (limited to 'noncore/tools/calc2/main') (more/less context) (show whitespace changes)
-rw-r--r--noncore/tools/calc2/main/.cvsignore1
-rw-r--r--noncore/tools/calc2/main/calc.cpp103
-rw-r--r--noncore/tools/calc2/main/calc.h69
-rw-r--r--noncore/tools/calc2/main/engine.cpp221
-rw-r--r--noncore/tools/calc2/main/engine.h111
-rw-r--r--noncore/tools/calc2/main/instruction.h69
-rw-r--r--noncore/tools/calc2/main/main.cpp34
-rw-r--r--noncore/tools/calc2/main/main.pro12
-rw-r--r--noncore/tools/calc2/main/plugininterface.h45
-rw-r--r--noncore/tools/calc2/main/stdinstructions.h125
10 files changed, 790 insertions, 0 deletions
diff --git a/noncore/tools/calc2/main/.cvsignore b/noncore/tools/calc2/main/.cvsignore
new file mode 100644
index 0000000..6d678c6
--- a/dev/null
+++ b/noncore/tools/calc2/main/.cvsignore
@@ -0,0 +1 @@
config.in
diff --git a/noncore/tools/calc2/main/calc.cpp b/noncore/tools/calc2/main/calc.cpp
new file mode 100644
index 0000000..8c50c2c
--- a/dev/null
+++ b/noncore/tools/calc2/main/calc.cpp
@@ -0,0 +1,103 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include <qvaluelist.h>
22#include <qpe/qpeapplication.h>
23#include <qdir.h>
24#include <qwidgetstack.h>
25
26#include "calc.h"
27#include "plugininterface.h"
28
29calc::calc (QWidget * p, const char *n):QWidget (p, n)
30{
31 setCaption (tr ("Calculator"));
32
33// widgets
34 LCD = new QLCDNumber (this);
35 LCD->setMaximumSize (QSize (240, 30));
36 LCD->setNumDigits(12);
37LCD->setSegmentStyle(QLCDNumber::Filled);
38 pluginWidgetStack = new QWidgetStack (this);
39
40// layout widgets
41 calculatorLayout = new QVBoxLayout (this);
42 calculatorLayout->addWidget (LCD);
43 calculatorLayout->addWidget (pluginWidgetStack);
44
45// no formatting of display for now
46 connect (&engine, SIGNAL(display(double)), LCD, SLOT(display(double)));
47 connect (&engine, SIGNAL(display(const QString&)), LCD, SLOT(display(const QString&)));
48 connect (&engine, SIGNAL(setBinMode()), LCD, SLOT(setBinMode()));
49 connect (&engine, SIGNAL(setOctMode()), LCD, SLOT(setOctMode()));
50 connect (&engine, SIGNAL(setDecMode()), LCD, SLOT(setDecMode()));
51 connect (&engine, SIGNAL(setHexMode()), LCD, SLOT(setHexMode()));
52
53#ifndef NO_PLUGINS
54// load plugins
55 QValueList < Plugin >::Iterator mit;
56 for (mit = pluginList.begin (); mit != pluginList.end (); ++mit) {
57 (*mit).interface->release ();
58 (*mit).library->unload ();
59 delete (*mit).library;
60 }
61 pluginList.clear ();
62
63 QString path = QPEApplication::qpeDir() + "plugins/calculator";
64 QDir dir (path, "lib*.so");
65 QStringList list = dir.entryList ();
66
67 QStringList::Iterator it;
68 for (it = list.begin (); it != list.end (); ++it) {
69 CalcInterface *iface = 0;
70 QLibrary *lib = new QLibrary (path + "/" + *it);
71 Plugin plugin;
72 plugin.pluginWidget = 0;
73
74 if (lib->queryInterface (IID_Calc, (QUnknownInterface **) & iface) ==
75 QS_OK) {
76 plugin.library = lib;
77 plugin.interface = iface;
78 plugin.pluginWidget = plugin.interface->getPlugin(&engine,pluginWidgetStack);
79 if (plugin.pluginWidget)
80 pluginWidgetStack->addWidget (plugin.pluginWidget, pluginList.count());
81 pluginList.append (plugin);
82 } else {
83 delete lib;
84 }
85 }
86 setMode (1);
87#else
88// load simple interface
89#endif
90}
91
92calc::~calc ()
93{
94#ifndef NO_PLUGINS
95 QValueList < Plugin >::Iterator mit;
96 for (mit = pluginList.begin (); mit != pluginList.end (); ++mit) {
97 (*mit).interface->release ();
98 (*mit).library->unload ();
99 delete (*mit).library;
100 }
101#endif
102}
103
diff --git a/noncore/tools/calc2/main/calc.h b/noncore/tools/calc2/main/calc.h
new file mode 100644
index 0000000..b52356d
--- a/dev/null
+++ b/noncore/tools/calc2/main/calc.h
@@ -0,0 +1,69 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#ifndef CALC_H
22#define CALC_H
23
24#ifdef QT_NO_COMPONENT
25#define NO_PLUGINS
26#endif
27
28#include <qlayout.h>
29#include <qwidgetstack.h>
30
31#ifndef NO_PLUGINS
32#include <qvaluelist.h>
33#include <qpe/qlibrary.h>
34#endif
35
36#include "engine.h"
37#include "plugininterface.h"
38
39struct Plugin {
40#ifndef NO_PLUGINS
41 QLibrary *library;
42#endif
43 QWidget *pluginWidget;
44 CalcInterface *interface;
45 QString name;
46};
47
48class calc:public QWidget {
49
50Q_OBJECT
51public:
52 calc (QWidget * p = 0, const char *n = 0);
53 ~calc ();
54
55private:
56#ifndef NO_PLUGINS
57 void loadPlugins ();
58 QValueList < Plugin > pluginList;
59#endif
60 QVBoxLayout *calculatorLayout;
61 QWidgetStack *pluginWidgetStack;
62 QLCDNumber *LCD;
63 Engine engine;
64
65public slots:
66 void setMode(int m){pluginWidgetStack->raiseWidget(m);};
67};
68
69#endif
diff --git a/noncore/tools/calc2/main/engine.cpp b/noncore/tools/calc2/main/engine.cpp
new file mode 100644
index 0000000..74cd701
--- a/dev/null
+++ b/noncore/tools/calc2/main/engine.cpp
@@ -0,0 +1,221 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "engine.h"
22
23/* OPIE */
24#include <opie2/odebug.h>
25
26/* QT */
27#include <qstring.h>
28#include <qlcdnumber.h>
29
30/* STD */
31#include <math.h>
32
33Data Engine::evalStack (Data num, bool inbrace = FALSE)
34{
35 if (state != sError) {
36 Instruction *i;
37
38// Pop the next op from the stack
39 while (!stack.isEmpty () && (braces || !inbrace)) {
40 i = stack.pop ();
41
42// Check this ops prec vs next ops prec
43 if (!stack.isEmpty ())
44 if (i->precedence <= stack.top()->precedence)
45 i->acc = evalStack (i->acc, inbrace);
46
47// Evaluate this instruction
48 num = i->eval (num);
49
50// Error-check ( change this to work for all types )
51 if (isnan (num.dbl) || isinf (num.dbl)) {
52 odebug << "bad result from operation" << oendl;
53 state = sError;
54 clearData(&num);
55 return num;
56 }
57 }
58 }
59 return num;
60}
61
62// Plugins call this to request the stack be evaluated
63void Engine::eval ()
64{
65 num = evalStack (num);
66 if (state != sError) {
67 displayData(num);
68 state = sStart;
69 }
70// if the user didnt close all their braces, its no big deal
71 braces = 0;
72}
73
74void Engine::immediateInstruction (Instruction * i)
75{
76 if (state != sError) {
77 i->setRep(currentRep);
78 num = i->eval (num);
79 displayData(num);
80 state = sStart;
81 }
82}
83
84void Engine::pushInstruction (Instruction * i)
85{
86 if (state != sError) {
87 i->setRep(currentRep);
88 i->acc = num;
89 stack.push (i);
90 state = sStart;
91 }
92}
93
94void Engine::pushValue (char v)
95{
96 if (state == sAppend) {
97 bool ok = FALSE;
98 switch (currentRep) {
99 case rDouble:
100 displayString.append(v);
101 num.dbl=displayString.toDouble(&ok);
102 break;
103 case rFraction:
104 break;
105 default:
106 displayString.append(v);
107 num.i=displayString.toInt(&ok, calcBase());
108 };
109 if (!ok) {
110 state = sError;
111 odebug << "pushValue() - num->string conversion" << oendl;
112 } else {
113 const QString constString = displayString;
114 emit(display(constString));
115 };
116
117 } else if (state == sStart) {
118 softReset();
119 displayString.truncate(0);
120 state = sAppend;
121 pushValue (v);
122 } else if (state == sError) {
123 odebug << "in error state" << oendl;
124 return;
125 }
126}
127
128void Engine::del ()
129{
130 bool ok;
131 switch (currentRep) {
132 case rDouble:
133 displayString.truncate(displayString.length());
134 num.dbl=displayString.toDouble(&ok);
135 break;
136 case rFraction:
137 odebug << "not available" << oendl;
138 break;
139 default:
140 displayString.truncate(displayString.length());
141 num.i = displayString.toInt(&ok, calcBase());
142 };
143
144 if (!ok) {
145 state = sError;
146 odebug << "del() - num->string conversion" << oendl;
147 } else {
148 const QString constString = displayString;
149 emit(display(constString));
150 };
151}
152
153void Engine::displayData(Data d) {
154 switch (currentRep) {
155 case rDouble:
156 displayString.setNum(d.dbl);
157 break;
158 case rFraction:
159 odebug << "fractional display not yet impl" << oendl;
160 break;
161 default:
162 displayString.setNum(d.i, calcBase());
163 break;
164 };
165 const QString constString= displayString;
166 emit(display(constString));
167}
168
169// Returns the base when Rep is an integer type
170int Engine::calcBase () {
171 switch (currentRep) {
172 case rBin:
173 return 2;
174 case rOct:
175 return 8;
176 case rDec:
177 return 10;
178 case rHex:
179 return 16;
180 default:
181 state = sError;
182 odebug << "Error - attempt to calc base for non-integer" << oendl;
183 return 10;
184 };
185}
186
187// Special instruction for internal use only
188class iOpenBrace:public Instruction {
189 public:
190 iOpenBrace (Engine *e):Instruction (100) {engine = e;};
191 ~iOpenBrace () {};
192
193 Data eval (Data num) {
194 engine->decBraces();
195 return num;
196 };
197 private:
198 Engine *engine;
199};
200
201void Engine::openBrace() {
202 pushInstruction(new iOpenBrace(this));
203}
204
205void Engine::closeBrace() {
206 braces++;evalStack(num,TRUE);
207}
208
209// will need to show and hide display widgets
210void Engine::setRepresentation(Representation r) {
211 currentRep = r;
212 clearData(&num);
213 clearData(&mem);
214 state = sStart;
215}
216
217void Engine::clearData(Data *d) {
218 d->i = d->fraction.numerator = d->fraction.denominator = 0;
219 d->dbl = 0;
220}
221
diff --git a/noncore/tools/calc2/main/engine.h b/noncore/tools/calc2/main/engine.h
new file mode 100644
index 0000000..15c9aa1
--- a/dev/null
+++ b/noncore/tools/calc2/main/engine.h
@@ -0,0 +1,111 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#ifndef ENGINE_H
22#define ENGINE_H
23
24#include <qwidget.h>
25 #include <qstack.h>// Instruction stack
26 #include <qstring.h>// Display
27#include "instruction.h"
28
29// Possible states
30enum State {
31 sStart,// start inputting a new number
32 sAppend,// continue inputting a number
33 sError
34};
35
36// State machine
37class Engine:public QWidget {
38
39Q_OBJECT
40public:
41 Engine (QWidget * parent = 0, const char *name = 0):QWidget (parent, name) {
42 hardReset();
43 setRepresentation(rDec);
44 };
45
46 ~Engine () { };
47
48 void immediateInstruction (Instruction *);
49 void pushInstruction (Instruction *);
50 void eval ();
51
52 void pushValue (char);
53 void del ();
54
55 void openBrace ();
56 void closeBrace ();
57
58 void softReset () {// clears the number being inputted
59 decimalPlaces = -1;
60 clearData(&num);
61 displayData(num);
62 state = sStart;
63 };
64 void hardReset () {// a "real" reset of the stack
65 stack.clear ();
66 memClear();
67 braces = 0;
68 softReset ();
69 };
70
71 void memSave () {
72 mem = num;
73 };
74 void memRecall () {
75 num = mem;
76 state = sStart;
77 displayData(num);
78 };
79 void memClear () {
80 clearData(&mem);
81 };
82
83 // rFraction will require a special display enabled here
84 void setRepresentation(Representation);
85
86 // you dont want to call this
87 void decBraces(void){ braces--; };
88
89private:
90 void displayData(Data d);
91 void clearData(Data *d);
92 int calcBase();
93 Data evalStack (Data, bool);
94 Data num,mem;
95 State state;
96 QStack < Instruction > stack;
97 Representation currentRep;
98 int braces, decimalPlaces; // count of finishing 0's in num
99 QString displayString; // saves instatiating it over and over
100
101signals:
102 void display(const QString &);
103 void display(double); // could get rid of this and
104 // use a QLabel instead.
105 void setHexMode();
106 void setBinMode();
107 void setDecMode();
108 void setOctMode();
109};
110
111#endif
diff --git a/noncore/tools/calc2/main/instruction.h b/noncore/tools/calc2/main/instruction.h
new file mode 100644
index 0000000..6077bf0
--- a/dev/null
+++ b/noncore/tools/calc2/main/instruction.h
@@ -0,0 +1,69 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef INSTRUCTION_H
21#define INSTRUCTION_H
22
23/* Internal representation of data
24The first four types indicate an int,
25that is, Data.i, and are incompatible
26with the other two types.
27
28- Plugin is responsible for telling engine
29which Rep to use at any given time
30- Instructions from that plugin only
31have to handle that representation
32- Engine is responsible for error-checking
33according to its current rep and display */
34enum Representation {
35 rBin,
36 rOct,
37 rDec,
38 rHex,
39 rDouble,
40 rFraction
41};
42
43// An atom of data
44union Data {
45 int i;
46 double dbl;
47 struct Fraction {
48 int numerator, denominator;
49 } fraction;
50};
51
52// Instruction base class
53class Instruction {
54public:
55 Instruction (int p = 0) {
56 precedence = p;
57 };
58
59 virtual ~ Instruction () {};
60
61 virtual Data eval(Data) = 0;
62 void setRep(Representation r) { rep = r; };
63
64 Representation rep;
65 Data acc;
66 int precedence;
67};
68
69#endif
diff --git a/noncore/tools/calc2/main/main.cpp b/noncore/tools/calc2/main/main.cpp
new file mode 100644
index 0000000..ebfcc28
--- a/dev/null
+++ b/noncore/tools/calc2/main/main.cpp
@@ -0,0 +1,34 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include <qpe/qpeapplication.h>
21#include "calc.h"
22
23int main (int argc, char **argv)
24{
25 QPEApplication a (argc, argv);
26
27 calc mw;
28
29 QPEApplication::setInputMethodHint (&mw, QPEApplication::AlwaysOff);
30 mw.setCaption (calc::tr ("Calculator"));
31 a.showMainWidget (&mw);
32
33 return a.exec ();
34}
diff --git a/noncore/tools/calc2/main/main.pro b/noncore/tools/calc2/main/main.pro
new file mode 100644
index 0000000..e2eda1f
--- a/dev/null
+++ b/noncore/tools/calc2/main/main.pro
@@ -0,0 +1,12 @@
1TEMPLATE = app
2CONFIG += qt
3# Input
4HEADERS += calc.h plugininterface.h instruction.h engine.h stdinstructions.h
5SOURCES += calc.cpp main.cpp engine.cpp
6INCLUDEPATH += $(OPIEDIR)/include
7DEPENDPATH += $(OPIEDIR)/include
8LIBS += -lqpe -Wl,-export-dynamic
9TARGET = calc2
10DESTDIR = $(OPIEDIR)/bin
11
12include( $(OPIEDIR)/include.pro )
diff --git a/noncore/tools/calc2/main/plugininterface.h b/noncore/tools/calc2/main/plugininterface.h
new file mode 100644
index 0000000..df6db9d
--- a/dev/null
+++ b/noncore/tools/calc2/main/plugininterface.h
@@ -0,0 +1,45 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#ifndef CALCINTERFACE_H
22#define CALCINTERFACE_H
23
24#include <qnamespace.h>
25#include <qstring.h>
26#include <qlcdnumber.h>
27#include <qpe/qcom.h>
28
29#include "engine.h"
30
31#ifndef QT_NO_COMPONENT
32// {3CE88B66-B3FD-4580-9D04-77338A31A667}
33#ifndef IID_Calc
34#define IID_Calc QUuid( 0x3ce88b66, 0xb3fd, 0x4580, 0x9d, 0x04, 0x77, 0x33, 0x8a, 0x31, 0xa6, 0x67)
35#endif
36#endif
37
38class QWidget;
39class QObject;
40
41struct CalcInterface:public QUnknownInterface {
42 virtual QWidget *getPlugin (Engine *e, QWidget * parent) = 0;
43};
44
45#endif
diff --git a/noncore/tools/calc2/main/stdinstructions.h b/noncore/tools/calc2/main/stdinstructions.h
new file mode 100644
index 0000000..a575968
--- a/dev/null
+++ b/noncore/tools/calc2/main/stdinstructions.h
@@ -0,0 +1,125 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#ifndef STDINSTRUCTION_H
22#define STDINSTRUCTION_H
23
24#include <qpe/qmath.h>
25#include "instruction.h"
26
27// Useful instructions for plugin writers
28// If you use them, take note of their precedence
29class iAdd:public Instruction {
30public:
31 iAdd ():Instruction (10) { };
32 ~iAdd () { };
33 Data eval (Data num) {
34 Data result;
35 switch (rep) {
36 case rDouble:
37 result.dbl = acc.dbl + num.dbl;
38 break;
39 default:
40 result.i = acc.i + num.i;
41 };
42 return result;
43 };
44};
45class iSub:public Instruction {
46public:
47 iSub ():Instruction (10) { };
48 ~iSub () { };
49 Data eval (Data num) {
50 Data result;
51 switch (rep) {
52 case rDouble:
53 result.dbl = acc.dbl - num.dbl;
54 break;
55 default:
56 result.i = acc.i - num.i;
57 };
58 return result;
59 };
60};
61class iMul:public Instruction {
62public:
63 iMul ():Instruction (20) { };
64 ~iMul () { };
65 Data eval (Data num) {
66 Data result;
67 switch (rep) {
68 case rDouble:
69 result.dbl = acc.dbl * num.dbl;
70 break;
71 default:
72 result.i = acc.i * num.i;
73 };
74 return result;
75 };
76};
77class iDiv:public Instruction {
78public:
79 iDiv ():Instruction (20) { };
80 ~iDiv () { };
81 Data eval (Data num) {
82 Data result;
83 switch (rep) {
84 case rDouble:
85 result.dbl = acc.dbl / num.dbl;
86 break;
87 default:
88 result.i = acc.i / num.i;
89 };
90 return result;
91 };
92};
93
94// Immediate double instructions only
95class iSin:public Instruction {
96public:
97 iSin ():Instruction () { };
98 ~iSin () { };
99 Data eval (Data num) {
100 Data result;
101 result.dbl = qSin(num.dbl);
102 return result;
103 };
104};
105class iCos:public Instruction {
106public:
107 iCos ():Instruction () { };
108 ~iCos () { };
109 Data eval (Data num) {
110 Data result;
111 result.dbl = qCos(num.dbl);
112 return result;
113 };
114};
115class iTan:public Instruction {
116public:
117 iTan ():Instruction () { };
118 ~iTan () {};
119 Data eval (Data num) {
120 Data result;
121 result.dbl = qTan(num.dbl);
122 return result;
123 };
124};
125#endif