             }
         }
     }
-    if let last = extrema.last where p.eval(last).almostZero() {
+    if let last = extrema.last where p.eval(last).almostZero(reference: last) {
         result.append(last)
     }
     return result

                    mid = 0.5 * (neg + pos)
                }
                let midVal = p.eval(mid)
                if midVal.almostZero(reference: midVal) || pos.almostEqual(neg) {
                    result.append(mid)
                    break
                }

        let left = p.eval(extrema[idx])
        let right = p.eval(extrema[idx + 1])
        
        if left.almostZero(reference: extrema[idx]) {
            if !result.contains(extrema[idx]) {
                result.append(extrema[idx])
            }
            
        } else if !right.almostZero(reference: extrema[idx + 1]) && left.isSignMinus != right.isSignMinus {
            var neg: Double
            var pos: Double
            if left > 0 {
