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 CCC867F98F for ; Tue, 1 Aug 2017 12:47:29 +0200 (CEST) Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=vietlq85@gmail.com; spf=Pass smtp.mailfrom=vietlq85@gmail.com; spf=None smtp.helo=postmaster@mail-yw0-f181.google.com Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of vietlq85@gmail.com) identity=pra; client-ip=209.85.161.181; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="vietlq85@gmail.com"; x-sender="vietlq85@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of vietlq85@gmail.com designates 209.85.161.181 as permitted sender) identity=mailfrom; client-ip=209.85.161.181; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="vietlq85@gmail.com"; x-sender="vietlq85@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-yw0-f181.google.com) identity=helo; client-ip=209.85.161.181; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="vietlq85@gmail.com"; x-sender="postmaster@mail-yw0-f181.google.com"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3AUhNS+xekvpyNgP/2ju/QElV/lGMj4u6mDksu8pMi?= =?us-ascii?q?zoh2WeGdxcu6bR7h7PlgxGXEQZ/co6odzbGH4+a4ASQp2tWoiDg6aptCVhsI24?= =?us-ascii?q?09vjcLJ4q7M3D9N+PgdCcgHc5PBxdP9nC/NlVJSo6lPwWB6nK94iQPFRrhKAF7?= =?us-ascii?q?Ovr6GpLIj8Swyuu+54Dfbx9GiTe5Yr5+Ngm6oRnMvcQKnIVuLbo8xAHUqXVSYe?= =?us-ascii?q?RWwm1oJVOXnxni48q74YBu/SdNtf8/7sBMSar1cbg2QrxeFzQmLns65Nb3uhnZ?= =?us-ascii?q?TAuA/WUTX2MLmRdVGQfF7RX6XpDssivms+d2xSeXMdHqQb0yRD+v6bpgRh31hy?= =?us-ascii?q?cdLzM38G/ZhM9tgqxFvB2svAZwz5LObYyPKPZyYqHQcNUHTmRBRMZRUClBD5uz?= =?us-ascii?q?YIsOEeUBIftToY/jqFATqha+GwisC/3zyj9Mn3/73q033v8uEQHDxgMgHtYOvG?= =?us-ascii?q?7Io9XyMacfSOa4x7TGwzXEavNZwzb96I7QfxAuoPGMQbJwcdfKxkU1CwzFiVCQ?= =?us-ascii?q?pIr4ND2WzuQAq3aX4/ZkWO61iGMqqxt9riWuy8sxkIXFm4EYxk3C+C5k2og6P8?= =?us-ascii?q?e4R1R+YdO8EJtfqSWaN4xuT8MnWW5ouSI6xqQGuJ+1YCQG0ZonywPcZvCaaYSI?= =?us-ascii?q?7RXjVOGeITd8mn1pYq6whxG38US4y+38UNe70EpSoyZbjtXBsmoB2h/T58SdV/?= =?us-ascii?q?dw/1qt1SyS2w3Q9+1IOUU0mrDaK54lzL4wjJ0TsUHbEy/omUX5krOWdkE9+uWr?= =?us-ascii?q?6+nqebrmppqGOI91jgHyKLghmsu6AeggKAgBQ3Cb+fig1L3k5UD2XK9Fjvgykq?= =?us-ascii?q?XAtJDaJN8bprKiDg9O0ocj7g6/AC283NQZm3kHNlNFdwidg4jnIVGdaMz/WPy2?= =?us-ascii?q?hlDplDZw29jHOKfgC9PDNCvtirDkKIh85lIU7Ad7mc5e6o5QE+FcCP32U0718t?= =?us-ascii?q?ffC0lqYESP3+/7BYAlhcslUmWVD/rBPQ=3D=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0DcAADPWoBZhrWhVdFdHQEXAQYBDBgHh?= =?us-ascii?q?AZtJweFJJheiw9Kg3aIKoISDhqFH4QYBz8YAQEBAQEBAQEBAQESAQEBCAsLCCg?= =?us-ascii?q?vgjMigm0EGQEbHgMSCQc3AiQBEQEFAYpLAQMVniuDRT+MCoFsGAUBHIMJBYNXC?= =?us-ascii?q?hknDVZHgwAeAgEFEoMWggKLIFMfgkeCYQWBLQEBnjsIAQGBUAoOhWiMWJJBlC8?= =?us-ascii?q?UH4EVH4FCd3hchDGBdD82h3CCPwEBAQ?= X-IPAS-Result: =?us-ascii?q?A0DcAADPWoBZhrWhVdFdHQEXAQYBDBgHhAZtJweFJJheiw9?= =?us-ascii?q?Kg3aIKoISDhqFH4QYBz8YAQEBAQEBAQEBAQESAQEBCAsLCCgvgjMigm0EGQEbH?= =?us-ascii?q?gMSCQc3AiQBEQEFAYpLAQMVniuDRT+MCoFsGAUBHIMJBYNXChknDVZHgwAeAgE?= =?us-ascii?q?FEoMWggKLIFMfgkeCYQWBLQEBnjsIAQGBUAoOhWiMWJJBlC8UH4EVH4FCd3hch?= =?us-ascii?q?DGBdD82h3CCPwEBAQ?= X-IronPort-AV: E=Sophos;i="5.41,305,1498514400"; d="scan'208,217";a="285696484" Received: from mail-yw0-f181.google.com ([209.85.161.181]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 01 Aug 2017 12:47:28 +0200 Received: by mail-yw0-f181.google.com with SMTP id u207so7296302ywc.3 for ; Tue, 01 Aug 2017 03:47:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=zq7SVsMtUW22ngZQ+/srlm8PQuJG00QZG68x4yqNtJY=; b=oWEZydAOACHuDvZ0yeHXyS/cYSGnTruu+uX4e3AQjqFzktdNEOIpQbmYdadeTsTPno nhK5o0bfwXqz1y506WxvwnXUzqwaKD/we1KDaQ/mAV0WrQ2Uu//r2bSjjWbp2vIZcTEx 3VpCtn2ZGT+/WpijjmQnoCA57iEzxEM+u2hOTZoicLmYmDg6ohSmxDsARtY0iGWQPpg1 pHBQ5WoDrFeYOduAxWT1yOPCBXEbEjZ6ww4ADV/JxRVN5R5OdJufw1XJoaRhH61e1YEp OXI/3KAlMychmn6/9R6j4nEv4AfP74uhGk955QAx3JWGmcDVCIkVVJvWyRHxrinbKv/3 xdsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=zq7SVsMtUW22ngZQ+/srlm8PQuJG00QZG68x4yqNtJY=; b=rjR5+8Wmcb3Q6rjfo3UHKjgq7tXUv6Li7lttbFHoFK1EwX50ZUiGFtBF6LvSt4YVbo 3lXYL/hGF7kluJ+AkHISCbqLROvcvYmmbkXfFi0gQ61DlSCfCdy84Te4BEp+JD7spciI bnuG+sbxQa348MuQzhuQUHpdd/1R1w5sTSg16VScZOyyhTrxmq992d30fwjHEIcJdXtN 2RT4fYLhXzoAN+PJoE0xsUjb6WaoaX2qzZjfBIY7TPrgS4XIqcwGN3a4RqPb6PRidrP3 +mGzir98funX3monFGUxaHRT/7BI4gsYm6rEKIyJNziNoiN+Il2AW5YPRXygCObESdxb I9Zw== X-Gm-Message-State: AIVw111Z1KVsr1AeK59gKCd9sogAAf3SoPmSzqeGP5C6J4qaW+UldFw5 OYqAGprhOiNu05u3jG02vN1C4LG33/dgriI= X-Received: by 10.37.43.73 with SMTP id r70mr15815733ybr.179.1501584447742; Tue, 01 Aug 2017 03:47:27 -0700 (PDT) MIME-Version: 1.0 Received: by 10.129.164.76 with HTTP; Tue, 1 Aug 2017 03:47:27 -0700 (PDT) From: Viet Le Date: Tue, 1 Aug 2017 11:47:27 +0100 Message-ID: To: caml-list@inria.fr Content-Type: multipart/alternative; boundary="94eb2c1351069bc2290555aedf4b" Subject: [Caml-list] Float precision in OCaml --94eb2c1351069bc2290555aedf4b Content-Type: text/plain; charset="UTF-8" Hi all, I'm writing a JSON parser in pure OCaml and have encountered an issue with small float values: 10 zeros in between # 1.00000000001e-312 ;; - : float = 1.00000000001e-312 11 zeros in between # 1.000000000001e-312 ;; - : float = 1.00000000000341e-312 # 5e-324 ;; - : float = 4.94065645841e-324 I haven't found precise limit, but as a rule of thumb (*not precise*), for a positive float value to keep its precision, it *should* not be smaller than 1.00000000001e-312. To use JSON as precise serializer, it would be necessary to preserve accuracy. I checked https://github.com/ocaml/Zarith and it supports only big int & quotients, not floating point. For values smaller than the limit above, should I just treat as 2 values: (normalized: float, exponent: float), so we will have: 5e-324 -> (5, -324) Comments and suggestions are appreciated. Thanks. -- Kind regards, Viet --94eb2c1351069bc2290555aedf4b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi all,

I'm writing a JS= ON parser in pure OCaml and have encountered an issue with small float valu= es:

10 zeros in between
# 1.00000000001e-312 ;;
- : float =3D 1.00000000001e-312

11 zeros in between
# 1.000000000001e-312 ;;
- : float =3D 1.00000000000341e-312
=

# 5e-324 ;;<= /div>
- : float =3D 4.94065645841e-= 324


I haven't f= ound precise limit, but as a rule of thumb (not precise), for= a positive float value to keep its precision, it should not = be smaller than=C2=A01.0000= 0000001e-312. To use JSON as precise serializer, it would be necessa= ry to preserve accuracy.

I checked=C2=A0https://github.com/ocaml/Zarith and it suppo= rts only big int & quotients, not floating point.

<= div>For values smaller than the limit above, should I just treat as 2 value= s: (normalized: float, exponent: float), so we will have:

5e-324 -> (5, -324)

Comments and suggestions are appreciated. = Thanks.

--
Kind regards,
Viet
--94eb2c1351069bc2290555aedf4b--