#!/usr/bin/ruby

# http://rosettacode.org/wiki/Roots_of_a_function

func f(x) {
    x*x*x - 3*x*x + 2*x;
}

var step = 0.001;
var start = -1;
var stop = 3;

range(start+step, stop, step).each { |x|
    static sign = false;
    var value = f(x);
    given (value) {
        when (0) {
            say "Root found at #{x}";
        }
        case (sign && ((value > 0) != sign)) {
            say "Root found near #{x}";
        }
    }
    sign = value>0;
}
