-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxll_array_sequence.cpp
More file actions
57 lines (50 loc) · 1.41 KB
/
xll_array_sequence.cpp
File metadata and controls
57 lines (50 loc) · 1.41 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
// xll_array_sequence.cpp - Arithmetic sequence.
#include "xll_array.h"
using namespace xll;
AddIn xai_array_sequence(
Function(XLL_FP, "xll_array_sequence", "ARRAY.SEQUENCE")
.Arguments({
Arg(XLL_DOUBLE, "start", "is the first value in the sequence.", "0"),
Arg(XLL_DOUBLE, "stop", "is the last value in the sequence.", "3"),
Arg(XLL_DOUBLE, "_incr", "is an optional value to increment by. Default is 1.")
})
.FunctionHelp("Return a one column array from start to stop with specified optional increment.")
.Category(CATEGORY)
.Documentation(R"(
Return a one columns array <code>{start; start + incr; ...; stop}<code>.
If <code>_incr</code> is greater than 1 return <code>_incr</code> values
from <code>start</code> to <code>stop</code>
)")
);
_FP12* WINAPI xll_array_sequence(double start, double stop, double incr)
{
#pragma XLLEXPORT
static xll::FPX a;
try {
if (incr == 0) {
incr = 1;
if (start > stop) {
incr = -1;
}
}
unsigned n;
if (incr > 1) {
n = static_cast<unsigned>(incr);
incr = (stop - start) / (n - 1);
}
else {
n = 1u + static_cast<unsigned>(fabs((stop - start) / incr));
}
a.resize(n, 1);
for (unsigned i = 0; i < n; ++i) {
a[i] = start + i * incr;
}
}
catch (const std::exception& ex) {
XLL_ERROR(ex.what());
}
catch (...) {
XLL_ERROR("ARRAY.SEQUENCE: unknown exception");
}
return a.get();
}