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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 402FF7FA6B for ; Tue, 25 Oct 2016 20:07:16 +0200 (CEST) Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=xavier.leroy@gmail.com; spf=Pass smtp.mailfrom=xavier.leroy@gmail.com; spf=None smtp.helo=postmaster@mail-wm0-f43.google.com Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of xavier.leroy@gmail.com) identity=pra; client-ip=74.125.82.43; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="xavier.leroy@gmail.com"; x-sender="xavier.leroy@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of xavier.leroy@gmail.com designates 74.125.82.43 as permitted sender) identity=mailfrom; client-ip=74.125.82.43; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="xavier.leroy@gmail.com"; x-sender="xavier.leroy@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-wm0-f43.google.com) identity=helo; client-ip=74.125.82.43; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="xavier.leroy@gmail.com"; x-sender="postmaster@mail-wm0-f43.google.com"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3A93zNqhAgZirLn0HmcODVUyQJP3N1i/DPJgcQr6Af?= =?us-ascii?q?oPdwSP38o8bcNUDSrc9gkEXOFd2CrakV0ayI7Ou5ADFIoc7Y9itdINoUD15NoP?= =?us-ascii?q?5VtjJjKfbNMVf8Iv/uYn5yN+V5f3ghwUuGN1NIEt31fVzYry76xzcTHhLiKVg9?= =?us-ascii?q?fbytScaBx/iwguu7/pmWZwRTmBK8Z6lzJVO4t1b/rM4T1LtrNKc80FPtr2FPaq?= =?us-ascii?q?wC9Wp2JF+J2TLx/MCh1J9l6SVZ/fw7oZ0TGZ7mdrg1GOQLRA8tNHo4sZXm?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0AmAQAhnw9YhitSfUpcHAEBBAEBCgEBF?= =?us-ascii?q?wEBBAEBCgEBgwQBAQEBAWc4QwULpDOeW0MQAQEBAQEBAQEBAQESAQEBCAsLCR0?= =?us-ascii?q?wgjMYghgBAQMBEhEdARInAwELAQUFGgImAgI0AQUBHBMIAQEeiBcDDwgEpzuBM?= =?us-ascii?q?j8yi0aESgWEBycNhBUCBhB3hTaBfQiCUIUTgjiCWwWaFl6POYlkDoYRjQiCPzG?= =?us-ascii?q?BETVvgUmBSoF/cIgRAQEB?= X-IPAS-Result: =?us-ascii?q?A0AmAQAhnw9YhitSfUpcHAEBBAEBCgEBFwEBBAEBCgEBgwQ?= =?us-ascii?q?BAQEBAWc4QwULpDOeW0MQAQEBAQEBAQEBAQESAQEBCAsLCR0wgjMYghgBAQMBE?= =?us-ascii?q?hEdARInAwELAQUFGgImAgI0AQUBHBMIAQEeiBcDDwgEpzuBMj8yi0aESgWEByc?= =?us-ascii?q?NhBUCBhB3hTaBfQiCUIUTgjiCWwWaFl6POYlkDoYRjQiCPzGBETVvgUmBSoF/c?= =?us-ascii?q?IgRAQEB?= X-IronPort-AV: E=Sophos;i="5.31,546,1473112800"; d="scan'208";a="242328978" Received: from mail-wm0-f43.google.com ([74.125.82.43]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 25 Oct 2016 20:07:04 +0200 Received: by mail-wm0-f43.google.com with SMTP id d128so41492472wmf.1 for ; Tue, 25 Oct 2016 11:07:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:subject:to:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=0vHzGO/0rqXOHwpJJ2kvYcVckcnZdZ12WTteVmzo6nM=; b=Bz5/BI64SFC17v8JrzoHluKA6O+BKW74gDfUFHxK2YRMDJ3MCqS1TnHNfJbXPRS/RN tj8NBJLxhjjQcLgWU3/NUjO9Qh8RXEAgYJthsIAWy8+mkqZKD4Lfx47CcksR5FyzaAoL WQSAD2xhr6t3xm/mwQEzSdrbsK+yWWUxzX/zxC0RHOQ7n4n077HNHH3V5duhPXTgL23d OYW04kSq/LPaywfg2qMhoreTeaHAt8xuJnOJ2B+/Ie8GDiAhx2mL0G+sGo0FnYXFiLwK BtTHBM6p79PjqDqmotbsG4Cqf5W4Mo6NkhlgFoxpKR7yx+uQbH56UHPrzQ6g/jmsSBbR c9LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:subject:to:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=0vHzGO/0rqXOHwpJJ2kvYcVckcnZdZ12WTteVmzo6nM=; b=Wa7I7RCD0trlhq/JPfR5hhZp6OVMAIJ3ocXLQA9FdzAYIWkfa8KzYyrvpxgFxKmKeh g8H3ZYwW7/HpRnQJOx0Cd+DIFGECjyz6PwIypfxs4mMefTB+hfxWIOSlKr8qIuvz7qw1 oMrv6tW8TxwGsVmyk79/BE2bI97rlmYdEPJ4yxlUGZzns8aahqFct7FrzUEzKpRhVgQo dufvxFFIwue3RQAjHkwFDjYTa8ayoxCX3PQ8gaqh0HPwVSiKAWqXenmu7BqS+SfjlZaf oZfIhqXzYIJS2QO2dN+Ux+et0XxyxYc+32QKI6f1wHcIe5WRg2w6GPHn6IfTgLAZJ6NZ t/9A== X-Gm-Message-State: ABUngvdSFo4A0yYkY4lP+OcbR0zJYTbM1zkqyE2ALfSvRrSHDhZ7QtFet2WY1rwInBLoqA== X-Received: by 10.28.146.130 with SMTP id u124mr4229814wmd.69.1477418824512; Tue, 25 Oct 2016 11:07:04 -0700 (PDT) Received: from [192.168.1.2] (che78-2-82-237-71-191.fbx.proxad.net. [82.237.71.191]) by smtp.gmail.com with ESMTPSA id g142sm4978639wmd.2.2016.10.25.11.07.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Oct 2016 11:07:03 -0700 (PDT) Sender: Xavier Leroy To: caml-list@inria.fr References: <0F7D3B1B3C4B894D824F5B822E3E5A172CFA061B@IRSMSX102.ger.corp.intel.com> <25995371-4f79-352b-35fe-7edb92de8161@normalesup.org> <0F7D3B1B3C4B894D824F5B822E3E5A172CFA06ED@IRSMSX102.ger.corp.intel.com> From: Xavier Leroy Message-ID: <6ed7708d-1e70-7072-f537-dbe305da3b09@inria.fr> Date: Tue, 25 Oct 2016 20:07:02 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [Caml-list] Approximations when converting from string to float On 10/25/2016 06:58 PM, Tung Vu Xuan wrote: > Thanks for suggestions. Since I am using a library for interval arithmetic > [1], your idea becomes easier for me. > let intv_of_big_int bi = > let n = Big_int.num_bits_big_int bi in > if n <= 53 then > let bi_float = Big_int.float_of_big_int bi in > {low=bi_float;high=bi_float} > else begin > let n = n - 53 in > (* Extract top 53 bits of x *) > let top = Big_int.shift_right_big_int bi n in Yes, that's how I would go about it, too. But probably you don't need the interval arithmetic in the end: both "top" and "top + 1" convert to floats without rounding (*), and the scaling by 2^n can be achieved with "ldexp". (*) If "top" is 2^53 - 1, "top + 1" is 2^53, which converts exactly. Otherwise, "top + 1" has at most 53 digits and converts exactly as well. Jacques-Henri Jourdan adds: > But really, you should use ZArith, which is much more modern, faster > and well-maintained than Big_int. Agreed. And if you must use Big_int.float_of_big_int, make sure you're using OCaml 4.03.0 or later, because older versions were flaky. - Xavier Leroy