Re: gmpy adapter - Mailing list psycopg

From Daniel Popowich
Subject Re: gmpy adapter
Date
Msg-id 19821.12117.630296.800838@io.astro.umass.edu
Whole thread Raw
In response to Re: gmpy adapter  (Daniele Varrazzo <daniele.varrazzo@gmail.com>)
Responses Re: gmpy adapter  (Daniele Varrazzo <daniele.varrazzo@gmail.com>)
List psycopg
Daniele Varrazzo writes:
> If cdecimal is good for you (i.e. if the decimal semantics is fine),
> you may use mpf throughout your program instead of mpq. It is an
> exact type (as exact as decimal of course: you can't represent all
> the rationals) and likely to be more efficient than mpq. Plus, it
> maps directly with the postgres decimal on I/O.
>

Really?  But it's binary floating point.  From the GMP manual,
http://gmplib.org/manual-4.3.2/Floating_002dpoint-Functions.html:

    The mantissa in stored in binary, as might be imagined from the
    fact precisions are expressed in bits. One consequence of this is
    that decimal fractions like 0.1 cannot be represented exactly. The
    same is true of plain IEEE double floats. This makes both highly
    unsuitable for calculations involving money or other values that
    should be exact decimal fractions. (Suitably scaled integers, or
    perhaps rationals, are better choices.)

> cdecimal may make your life easier instead if you have already
> working code using the Python Decimal and you want to speed it up.

First in importance is performance, but correctness cannot be
compromised.  Python Decimal semantics are fine for my application,
but performance is too slow.  A drop in replacement like cdecimal
makes life easier, but if a faster solution is available, I'll
exchange ease of use for performance.

Dan

psycopg by date:

Previous
From: Daniel Popowich
Date:
Subject: Re: gmpy adapter
Next
From: Daniele Varrazzo
Date:
Subject: Re: gmpy adapter