From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr 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 A946F7EFCD for ; Wed, 15 Oct 2014 12:43:25 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of drupyog+caml@zoho.com) identity=pra; client-ip=74.201.84.156; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="drupyog+caml@zoho.com"; x-sender="drupyog+caml@zoho.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of drupyog+caml@zoho.com designates 74.201.84.156 as permitted sender) identity=mailfrom; client-ip=74.201.84.156; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="drupyog+caml@zoho.com"; x-sender="drupyog+caml@zoho.com"; 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@sender1.zohomail.com) identity=helo; client-ip=74.201.84.156; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="drupyog+caml@zoho.com"; x-sender="postmaster@sender1.zohomail.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjwBAMtOPlRKyVScnGdsb2JhbABb2AQCgRgWAREBAQEBAQYNCQkULoQDAQEEMgEFCwE0Aw4LIRYPCQMCAQIBRQYBDAgBAReIDgEDAQQMBLF9hgACiHciKCWGNgELGQeQGzqESwGTB4pPgTCBF4UhO5FuaoJKAQEB X-IPAS-Result: AjwBAMtOPlRKyVScnGdsb2JhbABb2AQCgRgWAREBAQEBAQYNCQkULoQDAQEEMgEFCwE0Aw4LIRYPCQMCAQIBRQYBDAgBAReIDgEDAQQMBLF9hgACiHciKCWGNgELGQeQGzqESwGTB4pPgTCBF4UhO5FuaoJKAQEB X-IronPort-AV: E=Sophos;i="5.04,723,1406584800"; d="scan'208";a="83327097" Received: from sender1.zohomail.com ([74.201.84.156]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-MD5; 15 Oct 2014 12:43:23 +0200 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=zapps768; d=zoho.com; h=message-id:date:from:user-agent:mime-version:to:subject:references:in-reply-to:content-type; b=p79O/vZ16+eMPwm3p7nR13fXsEikyw1n0/xHG6p/SSizq57HhpRaC51ltwERx5c7FPwGdvGlvu3O MEtSODcPNHX+XStDHTr7pXsWa5/JKtzMGNcYFuWsiz9ODTe3eKbn Received: from [172.23.36.218] (maths.r-prg.net.univ-paris7.fr [81.194.27.158]) by mx.zohomail.com with SMTPS id 1413369675436320.5388590046946; Wed, 15 Oct 2014 03:41:15 -0700 (PDT) Message-ID: <543E4F48.9080304@zoho.com> Date: Wed, 15 Oct 2014 12:41:12 +0200 From: Drup User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.1.2 MIME-Version: 1.0 To: Marek Kubica , caml users References: <20141015112211.3e6bb721@xivilization.net> In-Reply-To: <20141015112211.3e6bb721@xivilization.net> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit X-ZohoMailClient: External X-Zoho-Virus-Status: 2 Subject: Re: [Caml-list] Divide and print with precision Why do you use Gmp ? Zarith already uses GMP under the hood and you can use the Q module for arbitrary precision rationals. Le 15/10/2014 11:22, Marek Kubica a écrit : > 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 >