Return-Path: X-Original-To: apmail-couchdb-user-archive@www.apache.org Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C0F4CD74D for ; Tue, 19 Feb 2013 15:15:46 +0000 (UTC) Received: (qmail 65438 invoked by uid 500); 19 Feb 2013 15:15:45 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 65061 invoked by uid 500); 19 Feb 2013 15:15:44 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 65027 invoked by uid 99); 19 Feb 2013 15:15:44 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 Feb 2013 15:15:44 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of paul.joseph.davis@gmail.com designates 209.85.214.180 as permitted sender) Received: from [209.85.214.180] (HELO mail-ob0-f180.google.com) (209.85.214.180) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 Feb 2013 15:15:37 +0000 Received: by mail-ob0-f180.google.com with SMTP id ef5so6799660obb.11 for ; Tue, 19 Feb 2013 07:15:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=5V+F1z5QRfBIgUZK1dy363myZgQ5uvZFMv25dfS+aN4=; b=FUMAi4NT3dgDgDeCuh8CCdRZlpc1Dx+qTZlqlnIpUSI88/XT753pPu1lP2QsGKYNn+ 1WL5Vn0Q+V+Q47thtD3UaKHy2lIAxm6IMR/ayrmcRFOj1tIUGEnB3auoWSsxKNg5PRuT 9+xOyGzd0ks2uoxOupftZik+NgXtw9g3mHxcXEHNVxzi0UjS3gmlu6K3DdB4oBSsaY7w P/bsdqemvjgwZeAVt7JC4/zpFPV586tPtP6LemR4VVDGtVGLpOTfUDI7hHI++1wnEVbS xVd3351HgVWLTS2Vi3IKaEP53sUs+2xcJpn3XzAW7tKT9Bj+/ZD9LwbrZF/SL06nR1/u fnJg== X-Received: by 10.60.170.44 with SMTP id aj12mr7591548oec.42.1361286916502; Tue, 19 Feb 2013 07:15:16 -0800 (PST) MIME-Version: 1.0 Received: by 10.60.135.132 with HTTP; Tue, 19 Feb 2013 07:14:36 -0800 (PST) In-Reply-To: <51238F3D.5050605@gmail.com> References: <51237473.8010601@gmail.com> <51238347.1090600@gmail.com> <51238F3D.5050605@gmail.com> From: Paul Davis Date: Tue, 19 Feb 2013 09:14:36 -0600 Message-ID: Subject: Re: Fixed precision of floating point number not respected in views To: Volker Mische Cc: "user@couchdb.apache.org" Content-Type: text/plain; charset=ISO-8859-1 X-Virus-Checked: Checked by ClamAV on apache.org Possible. Given what I know of JS and its numbers I wouldn't be highly optimistic that its not a mechanical turk. On Tue, Feb 19, 2013 at 8:42 AM, Volker Mische wrote: > I think it does address indexes. Only the JavaScript engine will deal > with the encoding/decoding. AFAIK SpiderMonkey/V8 doeas the right thing. > > Cheers, > Volker > > On 02/19/2013 02:53 PM, Paul Davis wrote: >> And doesn't address indexes. >> >> On Tue, Feb 19, 2013 at 7:51 AM, Volker Mische wrote: >>> Or we stop converting the document body into Erlang and store them as >>> raw JSON strings, so that there is no Erlang<->JSON conversion going on. >>> I know that's a big change. >>> >>> Cheers, >>> Volker >>> >>> On 02/19/2013 01:57 PM, Paul Davis wrote: >>>> It used mochijson2 which uses mochinum.erl which uses arbitrary >>>> precision arithmetic which makes this a lot easier (IIRC, its the >>>> ability to raise numbers to arbitrarily large powers). >>>> >>>> I do agree the behavior would be nice if it could be provided but the >>>> runtime cost is prohibitive if implemented in Erlang (arbitrary >>>> precision arithmetic is also generally slower than FPU operations). >>>> >>>> Also, so we're being more specific, it returned numbers with the >>>> fewest number of digits required that could then be fed into a >>>> standard libc parsing algorithm to return the same floating point >>>> representation based on what's in RAM. There are other assumptions and >>>> caveats related to the various thingers as well. >>>> >>>> On Tue, Feb 19, 2013 at 6:47 AM, Volker Mische wrote: >>>>> On 02/19/2013 10:13 AM, Paul Davis wrote: >>>>>> On Tue, Feb 19, 2013 at 3:09 AM, Robert Newson wrote: >>>>>>> "I have stored fixed precision numbers in a database". You haven't, >>>>>>> unfortunately, because you can't. Javascript only has one kind of >>>>>>> number, 64-bit floating point. >>>>>>> >>>>>> >>>>>> Its a tidge more complicated than that. Its actually a combination of >>>>>> the Erlang JSON decoder/encoder roundtrip plus the JavaScript decoder. >>>>> >>>>> I remember that older version of Apache CouchDB (IIRC 1.1) did return >>>>> the numbers as they were put it. Don't know which decoder was used back >>>>> then. >>>>> >>>>> I'd love to see this behaviour coming back. >>>>> >>>>> Cheers, >>>>> Volker >>>>> >>>>>> >>>>>>> >>>>>>> If you want fixed precision, you'll need to store your numbers in >>>>>>> strings and manipulate them that way too. A quick google in the past >>>>>>> has shown a few "bignum" libraries for Javascript. >>>>>>> >>>>>> >>>>>> Though the end result is the same. If you need fixed precision >>>>>> numbers, then using JSON's syntax for "numbers with decimal points and >>>>>> non-zero digits after the decimal point" will lead to surprising >>>>>> results and lack of fidelity. >>>>>> >>>>>> I've had a few discussions on this for Jiffy in terms of round >>>>>> tripping something as trivial as 1.1 through a JSON decoder/encoder >>>>>> pair. Turns out this is really really hard. >>>>>> >>>>>> Here's the Python ticket where they added it to the language for a >>>>>> good discussion on the details required to make this actually work: >>>>>> >>>>>> http://bugs.python.org/issue1580 >>>>>> >>>>>>> B. >>>>>>> >>>>>>> On 19 February 2013 08:20, Luca Morandini wrote: >>>>>>>> On 02/19/2013 07:05 PM, Luca Morandini wrote: >>>>>>>>> >>>>>>>>> Folks, >>>>>>>>> >>>>>>>>> I have stored fixed precision numbers in a database, but when they are >>>>>>>>> spit out by >>>>>>>>> a view, the precision is full, and -which is worse- the trailing decimal >>>>>>>>> digits >>>>>>>>> are not all zeroes. >>>>>>>> >>>>>>>> >>>>>>>> In the CouchDB: The Definitive Guide", I have found out that "most clients" >>>>>>>> would interpret, say, 15.7 as 15.69999999999 (or so), which I suppose is >>>>>>>> exactly what I observed... but what is meant as "client" in this context, a >>>>>>>> view engine ? >>>>>>>> >>>>>>>> Anyway, any view to tune this feature of the JavaScript view engine ? >>>>>>>> >>>>>>>> >>>>>>>> Regards, >>>>>>>> >>>>>>>> Luca Morandini >>>>>>>> Data Architect - AURIN project >>>>>>>> Department of Computing and Information Systems >>>>>>>> University of Melbourne >>>>>>>> Tel. +61 03 903 58 380 >>>>>>>> Skype: lmorandini >>>>>>>> >>>>> >>> >