Skip to content

Instantly share code, notes, and snippets.

@numinit
Created August 31, 2012 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save numinit/3555065 to your computer and use it in GitHub Desktop.
Save numinit/3555065 to your computer and use it in GitHub Desktop.
(i = ->(a, b, f) {
(
(opposite = ->(u, v){u < 0 && v > 0 || u > 0 && v < 0}).call(
f_a = f.call(a),
f_b = f.call(b)
) ?
(
(f_mid = f.call(mid = (a + b) / 2.0)).abs < Float::EPSILON ?
mid :
i.call(
(opposite.call(f_a, f_mid) ?
a :
mid),
(opposite.call(f_b, f_mid) ?
b :
mid),
f
)
) :
nil
)
}).call(-5, 5, ->(x) {(x + 1)**3})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment