Continued fraction/Arithmetic/G(matrix ng, continued fraction n1, continued fraction n2): Difference between revisions
Continued fraction/Arithmetic/G(matrix ng, continued fraction n1, continued fraction n2) (view source)
Revision as of 14:20, 10 March 2023
, 1 year ago→{{header|ATS}}
Line 432:
extern fn cf_get_at_size : {i : int} (cf, size_t i) -> integer
extern fn cf_get_at_int : {i : nat} (cf, int i) -> integer
extern fn cf2generator : cf -> cf_generator
(* The precedence of the overloads has to exceed that of ref[] *)
Line 469 ⟶ 471:
implement cf_get_at_int (cf, i) = cf_get_at_size (cf, g1i2u i)
implement
cf2generator cf =
let
in
lam () =>
let
in
!i := succ !i;
end
end
end (* local *)
Line 781 ⟶ 797:
cf_make
let
and xsource : ref cf_generator = ref (cf2generator x)
and ysource : ref cf_generator = ref (cf2generator y)
Size_t,▼
Size_t)▼
fn xsource (i : Size_t) :<cloref1> integer = x[i]▼
▲ val state_ref : ref state =
in
lam () =<cloref1>
let
fnx
let
val
val bz = iseqz
in
if
neginf<integerknd> ()
else if
absorb_x_term ()
else if
absorb_y_term ()
else if
absorb_x_term ()
else
Line 818 ⟶ 828:
and @(q2, r2) = a2 divrem b2
and @(q12, r12) =
(if
a12 divrem b12
else
@(neginf (), neginf ())) : @(integer, integer)
in
if (
begin (* Output a term. *)
!
q
end
Line 849 ⟶ 856:
absorb_x_term () : integer =
let
val
val term =
▲ val term = xsource i
in
if term <> neginf<integerknd> () then
Line 857 ⟶ 863:
try
let
val
and
and
and
and
and
and
and
in
!
(* Be aware: this is not a tail recursion! *)
end
with
Line 877 ⟶ 882:
(* Replace the sources with ones that return no
terms. (You have to replace BOTH sources.) *)
!
!xsource :=
!ysource
end
end
else
begin
!
recurs
▲ loop ()
end
end
Line 894 ⟶ 897:
absorb_y_term () : integer =
let
val
val term =
▲ val term = ysource j
in
if term <> neginf<integerknd> () then
Line 902 ⟶ 904:
try
let
val
and
and
and
and
and
and
and
in
!
(* Be aware: this is not a tail recursion! *)
end
with
Line 922 ⟶ 923:
(* Replace the sources with ones that return no
terms. (You have to replace BOTH sources.) *)
!
!xsource :=
!ysource
end
end
else
begin
!
recurs
end
end
in
end
end
|