Marek Kubica
2014-10-15 09:22:11 UTC
Hello,
I've got this short program here:
let prec = 1_000_000
let max_n = 205_211
let to_string = Gmp.F.to_string_base_digits ~base:10 ~digits:0
let euler_fraction n =
let open Z in
let numerator = ref one in
let denominator = ref one in
for i = 1 to n do
numerator := succ (!numerator * (of_int i));
denominator := (of_int i) * !denominator;
done;
(!numerator, !denominator)
let f () =
let (num, den) = euler_fraction max_n in
let znum = Gmp.F.from_string (Z.to_string num) in
let zden = Gmp.F.from_string (Z.to_string den) in
let euler = Gmp.F.div_prec ~prec znum zden in
print_endline @@ to_string euler
let () = f ()
It just computes e, using Zarith and Gmp. While Zarith works splendid,
I am having problems getting the division to work. I mean, it does
work, but I don't know how precise it is, because I can't get mlgmp to
print the 1_000_000 digits. From what I read in the GMP docs, 0 digits
means "whatever precision is available" but even if I explicitly
specify 1000 digits or so, the output is always
"2.718281828459045235360287471352662497757E0".
What can I do to get longer output? I don't insist on mlgmp (in fact,
it leaks memory like crazy, before I used Zarith I used mlgmp which
used 12 GB of RAM before I killed it), I just want some way to get a
base-10 floating point representation of my number.
Hope someone knows a solution.
regards,
Marek
I've got this short program here:
let prec = 1_000_000
let max_n = 205_211
let to_string = Gmp.F.to_string_base_digits ~base:10 ~digits:0
let euler_fraction n =
let open Z in
let numerator = ref one in
let denominator = ref one in
for i = 1 to n do
numerator := succ (!numerator * (of_int i));
denominator := (of_int i) * !denominator;
done;
(!numerator, !denominator)
let f () =
let (num, den) = euler_fraction max_n in
let znum = Gmp.F.from_string (Z.to_string num) in
let zden = Gmp.F.from_string (Z.to_string den) in
let euler = Gmp.F.div_prec ~prec znum zden in
print_endline @@ to_string euler
let () = f ()
It just computes e, using Zarith and Gmp. While Zarith works splendid,
I am having problems getting the division to work. I mean, it does
work, but I don't know how precise it is, because I can't get mlgmp to
print the 1_000_000 digits. From what I read in the GMP docs, 0 digits
means "whatever precision is available" but even if I explicitly
specify 1000 digits or so, the output is always
"2.718281828459045235360287471352662497757E0".
What can I do to get longer output? I don't insist on mlgmp (in fact,
it leaks memory like crazy, before I used Zarith I used mlgmp which
used 12 GB of RAM before I killed it), I just want some way to get a
base-10 floating point representation of my number.
Hope someone knows a solution.
regards,
Marek
--
Caml-list mailing list. Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs
Caml-list mailing list. Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs