-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalc.cpp
More file actions
executable file
·46 lines (33 loc) · 735 Bytes
/
Calc.cpp
File metadata and controls
executable file
·46 lines (33 loc) · 735 Bytes
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
#include <kroll/kroll.h>
#include "Calc.h"
#include "bmcalc.h"
namespace Titanium {
Calc::Calc(KObjectRef global) :
StaticBoundObject("Calc"),
global(global)
{
this->SetMethod("Minimum", &Calc::Minimum);
}
Calc::~Calc()
{
}
void Calc::Minimum(const ValueList& args, KValueRef result)
{
if (args.at(0)->IsList())
{
KListRef list = args.at(0)->ToList();
double *arr = NULL;
arr = new double[list->Size()];
for (unsigned int c = 0; c < list->Size(); c++)
{
KValueRef d = list->At(c);
arr[c] = d->ToDouble();
}
double low = Min(arr, list->Size());
result->SetDouble(low);
delete [] arr;
} else {
throw ValueException::FromString("Minimum takes an array");
}
}
} // namespace Titanium