-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxll_monoid.cpp
More file actions
65 lines (57 loc) · 1.47 KB
/
xll_monoid.cpp
File metadata and controls
65 lines (57 loc) · 1.47 KB
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
// xll_monoid.cpp
#include "fms_monoid.h"
#include "xll/xll/xll.h"
#ifndef CATEGORY
#define CATEGORY "Monoid"
#endif
using namespace xll;
AddIn xai_monoid_add(
Function(XLL_HANDLEX, "xll_monoid_add", "MONOID.ADD")
.Arguments({})
.Category(CATEGORY)
.FunctionHelp("Return handle to addition monoid.")
);
HANDLEX WINAPI xll_monoid_add()
{
#pragma XLLEXPORT
return safe_handle<const fms::monoid<double>>(&fms::monoid_add<double>);
}
AddIn xai_monoid_op(
Function(XLL_DOUBLE, "xll_monoid_op", "MONOID")
.Arguments({
Arg(XLL_HANDLEX, "op", "is a handle to a monoid."),
Arg(XLL_DOUBLE, "x", "is the first argument."),
Arg(XLL_DOUBLE, "y", "is the second argument."),
})
.Category(CATEGORY)
.FunctionHelp("Return op(x, y).")
);
double WINAPI xll_monoid_op(HANDLEX op, double x, double y)
{
#pragma XLLEXPORT
auto op_ = safe_pointer<fms::monoid<double>>(op);
if (op_) {
return (*op_)(x, y);
}
return XLL_NAN;
}
AddIn xai_monoid_scan(
Function(XLL_DOUBLE, "xll_monoid_scan", "MONOID.SCAN")
.Arguments({
Arg(XLL_HANDLEX, "op", "is a handle to a monoid."),
Arg(XLL_DOUBLE, "x", "is a number."),
})
.Uncalced()
.Category(CATEGORY)
.FunctionHelp("Return scan(x, y).")
);
double WINAPI xll_monoid_scan(HANDLEX op, double x)
{
#pragma XLLEXPORT
handle<fms::monoid<double>> op_(op);
if (op_) {
OPER cc = Excel(xlCoerce, Excel(xlfCaller));
return cc == 0 ? x : (*op_)(cc.as_num(), x);
}
return XLL_NAN;
}