@@ -147,7 +147,7 @@ FindRootResult!T findRoot(alias f, alias tolerance = null, T)(
147147 const T fax = - T.nan,
148148 const T fbx = + T.nan)
149149 if (
150- isFloatingPoint! T && __traits(compiles, {T _ = f(T.init);} ) &&
150+ isFloatingPoint! T && __traits(compiles, T( f(T.init)) ) &&
151151 (
152152 is (typeof (tolerance) == typeof (null )) ||
153153 __traits (compiles , {auto _ = bool (tolerance(T.init, T.init));}
@@ -160,31 +160,34 @@ FindRootResult!T findRoot(alias f, alias tolerance = null, T)(
160160 static if (! is (typeof (tolerance) == typeof (null )))
161161 bool b = tolerance(T(123 ), T(123 ));
162162 }
163- scope const T delegate (T) @safe pure nothrow @nogc fun = delegate (T x) {
163+ scope funInst = delegate (T x) {
164164 return T (f(x));
165- }.trustedAllAttr;
165+ };
166+
167+ scope fun = funInst.trustedAllAttr;
166168
167169 scope bool delegate (T, T) @safe pure nothrow @nogc tol;
168170 static if (! is (typeof (tolerance) == typeof (null )))
169171 {
170- tol = delegate (T a, T b) {
172+ scope tolInst = delegate (T a, T b) {
171173 return bool (tolerance(a, b));
172- }.trustedAllAttr;
174+ };
175+ tol = tolInst.trustedAllAttr;
173176 }
174177 return findRootImpl (ax, bx, fax, fbx, fun, tol);
175178}
176179
177180// /
178- version (mir_test) @safe unittest
181+ version (mir_test) @safe @nogc unittest
179182{
180183 import mir.math.common: log, exp;
181184
182185
183186 auto logRoot = findRoot! log(0 , double .infinity).validate.x;
184187 assert (logRoot == 1 );
185188
186- auto expm1Root = findRoot !
187- (x => exp(x) - 1 )
189+ auto shift = 1 ;
190+ auto expm1Root = findRoot ! (x => exp(x) - shift )
188191 (- double .infinity, double .infinity).validate.x;
189192 assert (expm1Root == 0 );
190193
@@ -879,15 +882,16 @@ FindLocalMinResult!T findLocalMin(alias f, T)(
879882 const T bx,
880883 const T relTolerance = sqrt(T.epsilon),
881884 const T absTolerance = sqrt(T.epsilon))
882- if (isFloatingPoint! T && __traits(compiles, {T _ = f(T.init);} ))
885+ if (isFloatingPoint! T && __traits(compiles, T( f(T.init)) ))
883886{
884887 if (false ) // break attributes
885888 {
886889 T y = f(T(123 ));
887890 }
888- scope const T delegate (T) @safe pure nothrow @nogc fun = delegate (T x) {
891+ scope funInst = delegate (T x) {
889892 return T (f(x));
890- }.trustedAllAttr;
893+ };
894+ scope fun = funInst.trustedAllAttr;
891895
892896 return findLocalMinImpl (ax, bx, relTolerance, absTolerance, fun);
893897}
@@ -1061,12 +1065,14 @@ do
10611065}
10621066
10631067// /
1064- version (mir_test) @safe unittest
1068+ version (mir_test) @safe @nogc unittest
10651069{
10661070 import mir.math.common: approxEqual;
10671071
1068- auto ret = findLocalMin! (x => (x- 4 )^^ 2 )(- 1e7 , 1e7 ).validate;
1069- assert (ret.x.approxEqual(4.0 ));
1072+ double shift = 4 ;
1073+
1074+ auto ret = findLocalMin! (x => (x- shift)^^ 2 )(- 1e7 , 1e7 ).validate;
1075+ assert (ret.x.approxEqual(shift));
10701076 assert (ret.y.approxEqual(0.0 ));
10711077}
10721078
0 commit comments