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

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

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