feat (notes): reorganise and update (and some formatting)
This commit is contained in:
parent
3b5e01b163
commit
dd6152833f
6 changed files with 211 additions and 209 deletions
29
exm/sqrt.ml
29
exm/sqrt.ml
|
|
@ -8,7 +8,7 @@ type s = Good | Bad
|
|||
|
||||
let with_nan = false
|
||||
|
||||
type state =
|
||||
type state =
|
||||
{ s_auto: s; (* active state of the automaton *)
|
||||
s_pos : carray;
|
||||
s_zin : zarray;
|
||||
|
|
@ -19,7 +19,7 @@ let sqrt () =
|
|||
let fder s y yd =
|
||||
yd.{0} <- -1.0;
|
||||
match s.s_auto with
|
||||
| Good ->
|
||||
| Good ->
|
||||
let o = if with_nan then sqrt y.{0}
|
||||
else if y.{0} >= 0.0 then sqrt y.{0} else 0.0 in
|
||||
yd.{1} <- o
|
||||
|
|
@ -27,9 +27,9 @@ let sqrt () =
|
|||
yd.{1} <- 0.0 in
|
||||
let fzero _ y zout = zout.{0} <- -. y.{0} in
|
||||
let fout state y =
|
||||
let o =
|
||||
let o =
|
||||
match state.s_auto with
|
||||
| Good -> let o =
|
||||
| Good -> let o =
|
||||
if with_nan then sqrt y.{0}
|
||||
else if y.{0} >= 0.0 then sqrt y.{0} else 0.0 in
|
||||
o
|
||||
|
|
@ -40,28 +40,27 @@ let sqrt () =
|
|||
| Good ->
|
||||
let o = if with_nan then sqrt s_pos.{0}
|
||||
else if s_pos.{0} >= 0.0 then sqrt s_pos.{0} else 0.0 in
|
||||
let state =
|
||||
if s_zin.{0} = 1l then { state with s_auto = Bad; s_encore = true }
|
||||
let state =
|
||||
if s_zin.{0} = 1l then { state with s_auto=Bad; s_encore=true }
|
||||
else state in
|
||||
let pos = of_array [| state.s_pos.{0}; state.s_pos.{1} |] in
|
||||
of_array [| o; state.s_pos.{0}; state.s_pos.{1} |],
|
||||
{ state with s_zin = zfalse; s_pos = pos }
|
||||
| Bad ->
|
||||
of_array [| o; state.s_pos.{0}; state.s_pos.{1} |],
|
||||
{ state with s_zin=zfalse; s_pos=pos }
|
||||
| Bad ->
|
||||
let o = 42.0 in
|
||||
let state = { state with s_encore = false;
|
||||
s_pos =
|
||||
of_array [| s_pos.{0}; 0.0 |] } in
|
||||
let state = { state with s_encore=false;
|
||||
s_pos=of_array [| s_pos.{0}; 0.0 |] } in
|
||||
of_array [| o; state.s_pos.{0}; state.s_pos.{1} |], state in
|
||||
let cget { s_pos; _ } = s_pos in
|
||||
let cset s l_x = { s with s_pos = l_x } in
|
||||
let zset s zin = { s with s_zin = zin } in
|
||||
let cset s l_x = { s with s_pos=l_x } in
|
||||
let zset s zin = { s with s_zin=zin } in
|
||||
let yd = cmake 2 in
|
||||
let zout = cmake 1 in
|
||||
let zsize = 1 in
|
||||
let s_init =
|
||||
{ s_encore = false;
|
||||
s_auto = Good;
|
||||
s_pos = of_array [| 13.3; 0.0 |];
|
||||
s_pos = of_array [| 13.3; 0.0 |];
|
||||
s_zin = zmake 1 } in
|
||||
let reset _ _ = s_init in
|
||||
let jump _ = true in
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue