From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id F414D7F057 for ; Wed, 15 Oct 2014 11:25:16 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of marek@xivilization.net) identity=pra; client-ip=178.63.18.39; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="marek@xivilization.net"; x-sender="marek@xivilization.net"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of marek@xivilization.net designates 178.63.18.39 as permitted sender) identity=mailfrom; client-ip=178.63.18.39; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="marek@xivilization.net"; x-sender="marek@xivilization.net"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@coaxial.xivilization.net) identity=helo; client-ip=178.63.18.39; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="marek@xivilization.net"; x-sender="postmaster@coaxial.xivilization.net"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AioOAAE9PlSyPxIn/2dsb2JhbABbgw5kA7l2miaBChYBfYRDBgEBODs0Ti6IJwGxbYV6AQWBAo9GBpEDhB2PZo1wgTGGM0CNdYFHAQuCJmqCSgEBAQ X-IPAS-Result: AioOAAE9PlSyPxIn/2dsb2JhbABbgw5kA7l2miaBChYBfYRDBgEBODs0Ti6IJwGxbYV6AQWBAo9GBpEDhB2PZo1wgTGGM0CNdYFHAQuCJmqCSgEBAQ X-IronPort-AV: E=Sophos;i="5.04,723,1406584800"; d="scan'208";a="83315399" Received: from coaxial.xivilization.net ([178.63.18.39]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES128-SHA; 15 Oct 2014 11:24:46 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xivilization.net; s=xiv; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-ID:Subject:To:From:Date; bh=MAwoUa5r2OqEId7LSR37bofp7qL7/wkj4qI6p3E8llM=; b=pIBv5F+yYtEERVaXVsCSUrpqeT+rG0oXWijAHGYXxm5eEpBBXESl6vhLG+VkP7F9j0WYfdZNeqXhEWSWBUY9RBVRhTItQFqjD2t6iA0aB6VHd76ep16wTli+y0cR4Wv9; Received: from aftr-88-217-180-198.dynamic.mnet-online.de ([88.217.180.198] helo=localhost.localdomain) by coaxial.xivilization.net with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1XeKp2-0002zj-DT for caml-list@inria.fr; Wed, 15 Oct 2014 11:24:44 +0200 Date: Wed, 15 Oct 2014 11:22:11 +0200 From: Marek Kubica To: caml users Message-ID: <20141015112211.3e6bb721@xivilization.net> X-Mailer: Claws Mail 3.10.1 (GTK+ 2.24.24; x86_64-unknown-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: [Caml-list] Divide and print with precision 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