// Generated by ReScript, PLEASE EDIT WITH CARE

import * as Curry from "rescript/lib/es6/curry.js";

function $neg(prim0, prim1) {
  return prim0 - prim1;
}

function $plus(prim0, prim1) {
  return prim0 + prim1;
}

function $star(prim0, prim1) {
  return prim0 * prim1;
}

function $slash(prim0, prim1) {
  return prim0 / prim1;
}

function newton(f, fPrimed, initial, threshold) {
  var current = {
    contents: initial
  };
  var iterateMore = function (previous, next) {
    var delta = next >= previous ? next - previous : previous - next;
    current.contents = next;
    return delta >= threshold;
  };
  var _param;
  while(true) {
    var previous = current.contents;
    var next = previous - Curry._1(f, previous) / Curry._1(fPrimed, previous);
    if (!iterateMore(previous, next)) {
      return current.contents;
    }
    _param = undefined;
    continue ;
  };
}

function f(x) {
  return x * x * x - 2.0 * x * x - 11.0 * x + 12.0;
}

function fPrimed(x) {
  return 3.0 * x * x - 4.0 * x - 11.0;
}

var result = newton(f, fPrimed, 5.0, 0.0003);

console.log(result, f(result));

export {
  $neg ,
  $plus ,
  $star ,
  $slash ,
  newton ,
  f ,
  fPrimed ,
  result ,
}
/* result Not a pure module */
