From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 0017FBBBB for ; Sun, 19 Feb 2006 17:53:24 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id k1JGrOMT025276 for ; Sun, 19 Feb 2006 17:53:24 +0100 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA32208 for ; Sun, 19 Feb 2006 17:53:23 +0100 (MET) Received: from conn.mc.mpls.visi.com (conn.mc.mpls.visi.com [208.42.156.2]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id k1JGrM56025272 for ; Sun, 19 Feb 2006 17:53:23 +0100 Received: from [192.168.42.2] (bhurt.dsl.visi.com [208.42.141.66]) by conn.mc.mpls.visi.com (Postfix) with ESMTP id EF7878187; Sun, 19 Feb 2006 10:53:21 -0600 (CST) Date: Sun, 19 Feb 2006 10:53:47 -0600 (CST) From: Brian Hurt X-X-Sender: bhurt@localhost.localdomain To: Richard Jones Cc: caml-list@inria.fr Subject: Re: [Caml-list] What library to use for arbitrary precision decimals In-Reply-To: <20060219163838.GA32465@furbychan.cocan.org> Message-ID: References: <20060219163838.GA32465@furbychan.cocan.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Miltered: at concorde with ID 43F8A284.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 43F8A282.002 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 integers:01 ocaml:01 datatype:01 semantics:01 stdlib:01 wrote:01 arbitrary:01 exception:01 define:01 hmm:02 floats:02 types:02 library:03 library:03 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 On Sun, 19 Feb 2006, Richard Jones wrote: > > Before we go too far down the currency track (where I agree, using > integers is the way to go), my actual requirement is for a natural > OCaml mapping for the PostgreSQL NUMERIC/DECIMAL type: > > http://www.postgresql.org/docs/current/interactive/datatype.html#DATATYPE-NUMERIC-DECIMAL > > The database can define types like NUMERIC(6,4) which means 6 decimal > digits in total, 4 of them after the decimal point -- for example, > 12.3456 Hmm. There are problems definin that library. What are the semantics? If I add a NUMERIC(6,4) (2 digits to the left of the point and 4 to the righ) and a NUMERIC(7,2) (5 digits to the left of the point and 2 to the right), what precision is the result? NUMERIC(4,2) (2 digits to the left of the point and 2 to the right)? NUMERIC(9,4) (5 digits to the left of the point and 4 digits to the right)? How does roundoff work? If I take the NUMERIC(6,4) number 62.0000 and multiply it by the NUMERIC(6,4) number 02.0000, what answer do I get? The NUMERIC(6,4) number 24.000? The NUMERIC(7,4) number 124.000? Or does it throw an exception? > > There doesn't seem to me to be a good natural map for this type in the > stdlib. If decimal roundoff isn't important, I'd be tempted to go for floats. I don't know if this is true or not. Brian