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 E34F8EA0F for ; Tue, 19 Feb 2013 17:33:56 +0000 (UTC) Received: (qmail 66045 invoked by uid 500); 19 Feb 2013 17:33:54 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 65991 invoked by uid 500); 19 Feb 2013 17:33:54 -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 65957 invoked by uid 99); 19 Feb 2013 17:33:54 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 Feb 2013 17:33:53 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of jens@couchbase.com designates 206.225.164.30 as permitted sender) Received: from [206.225.164.30] (HELO EXHUB020-3.exch020.serverdata.net) (206.225.164.30) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 Feb 2013 17:33:47 +0000 Received: from EXVMBX020-1.exch020.serverdata.net ([169.254.4.201]) by EXHUB020-3.exch020.serverdata.net ([206.225.164.30]) with mapi; Tue, 19 Feb 2013 09:33:25 -0800 From: Jens Alfke To: "user@couchdb.apache.org" Date: Tue, 19 Feb 2013 09:33:31 -0800 Subject: Re: Fixed precision of floating point number not respected in views Thread-Topic: Fixed precision of floating point number not respected in views Thread-Index: Ac4Oxzh9Q7+GpB1VSKS+aoU2rouVFw== Message-ID: <1CA1ECC0-5883-4714-9181-3E68B38FFAD6@couchbase.com> References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Virus-Checked: Checked by ClamAV on apache.org On Feb 19, 2013, at 1:09 AM, Robert Newson wrote: > 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. Another alternative, if you need a certain number of decimal digits of prec= ision, is to premultiply the numbers by a fixed power of ten. For example, = it looks like the OP may need five digits after the decimal point, so multi= plying the input values by 10^5 would turn them into integers. Then the val= ue 151.17281 would be stored as 15117281, which of course can be represente= d precisely in 64-bit floating point. (The limitation here is that since 64-bit doubles have a 56-bit mantissa (I= IRC), the largest integer that can be represented precisely is about 10^16,= corresponding to a pre-scaled input value of 10^11.) The obvious advantage over string encoding is that you can add, subtract an= d compare numbers without having to do any conversion, and even if you do h= ave to convert numbers (for multiplication, say) the conversion is very fas= t compared to string<->number conversions. As for alternative data formats, there are a lot of them around, and I don= =92t see that EDN would have an advantage over any of the others that are b= etter known and more widely adopted, like YAML. Changing away from JSON wou= ld be a compatibility nightmare, anyway (speaking as the author of a Couch-= compatible replication engine.) =97Jens=