Skip to content

Commit 6ec1598

Browse files
Add Specific Error for Brent Non-Convergence (#3)
1 parent 531ea2e commit 6ec1598

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

brentzero.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"math"
88
)
99

10+
var BrentBoundsError = errors.New("brent: f(a) * f(b) >= 0")
11+
1012
// Brent find zero of f using Brent's method
1113
// see https://en.wikipedia.org/wiki/Brent%27s_method
1214
// logger may be nil
@@ -25,7 +27,7 @@ func Brent(a, b, tol float64, f func(float64) float64, logger *log.Logger) (floa
2527
fa, fb := f(a), f(b)
2628
// si f(a) f(b) >= 0 alors sortie (erreur) fin si
2729
if fa*fb >= 0 {
28-
return math.NaN(), errors.New("brent: f(a) f(b) >= 0")
30+
return math.NaN(), BrentBoundsError
2931
}
3032
// si |f(a)| < |f(b)| alors échanger (a,b) fin si
3133
if abs(fa) < abs(fb) {

0 commit comments

Comments
 (0)