incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Davis <paul.joseph.da...@gmail.com>
Subject Re: Fixed precision of floating point number not respected in views
Date Tue, 19 Feb 2013 09:13:32 GMT
On Tue, Feb 19, 2013 at 3:09 AM, Robert Newson <rnewson@apache.org> 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.

>
> 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 <lmorandini@ieee.org> 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
>>

Mime
View raw message