The OpenD Programming Language

1 /++
2 This module contans extern C++ wrappers for $(MREF mir, numeric).
3 +/
4 module mir.cpp_export.numeric;
5 
6 import mir.numeric: findRootImpl, mir_find_root_result;
7 
8 private alias CFunction(T) = extern(C++) T function(scope const(void)* ctx, T) @safe pure nothrow @nogc;
9 
10 private alias CTolerance(T) = extern(C++) bool function(scope const(void)* ctx, T, T) @safe pure nothrow @nogc;
11 
12 export extern(C++) @safe pure nothrow @nogc:
13 
14 /// Wrapper for $(REF_ALTTEXT $(TT findRoot), findRoot, mir, numeric)$(NBSP)
15 mir_find_root_result!float mir_find_root(
16     float ax,
17     float bx,
18     float fax,
19     float fbx,
20     float lowerBound,
21     float upperBound,
22     uint maxIterations,
23     uint steps,
24     scope CFunction!float f,
25     scope const(void)* f_ctx,
26     scope CTolerance!float tolerance,
27     scope const(void)* tolerance_ctx,
28 )
29 {
30     pragma(inline, false);
31     if (tolerance is null)
32         return findRootImpl(ax, bx, fax, fbx, lowerBound, upperBound, maxIterations, steps, (float x) => f(f_ctx, x), null);
33     else
34         return findRootImpl(ax, bx, fax, fbx, lowerBound, upperBound, maxIterations, steps, (float x) => f(f_ctx, x), (float a, float b) => tolerance(tolerance_ctx, a, b) != 0);
35 }
36 
37 /// ditto
38 mir_find_root_result!double mir_find_root(
39     double ax,
40     double bx,
41     double fax,
42     double fbx,
43     double lowerBound,
44     double upperBound,
45     uint maxIterations,
46     uint steps,
47     scope CFunction!double f,
48     scope const(void)* f_ctx,
49     scope CTolerance!double tolerance,
50     scope const(void)* tolerance_ctx,
51 )
52 {
53     pragma(inline, false);
54     if (tolerance is null)
55         return findRootImpl(ax, bx, fax, fbx, lowerBound, upperBound, maxIterations, steps, (double x) => f(f_ctx, x), null);
56     else
57         return findRootImpl(ax, bx, fax, fbx, lowerBound, upperBound, maxIterations, steps, (double x) => f(f_ctx, x), (double a, double b) => tolerance(tolerance_ctx, a, b) != 0);
58 }
59 
60 /// ditto
61 mir_find_root_result!real mir_find_root(
62     real ax,
63     real bx,
64     real fax,
65     real fbx,
66     real lowerBound,
67     real upperBound,
68     uint maxIterations,
69     uint steps,
70     scope CFunction!real f,
71     scope const(void)* f_ctx,
72     scope CTolerance!real tolerance,
73     scope const(void)* tolerance_ctx,
74 )
75 {
76     pragma(inline, false);
77     if (tolerance is null)
78         return findRootImpl(ax, bx, fax, fbx, lowerBound, upperBound, maxIterations, steps, (real x) => f(f_ctx, x), null);
79     else
80         return findRootImpl(ax, bx, fax, fbx, lowerBound, upperBound, maxIterations, steps, (real x) => f(f_ctx, x), (real a, real b) => tolerance(tolerance_ctx, a, b) != 0);
81 }