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

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

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