Re: gmpy adapter

From: Daniel Popowich <danielpopowich(at)gmail(dot)com>
To: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
Cc: psycopg(at)postgresql(dot)org
Subject: Re: gmpy adapter
Date: 2011-03-01 17:39:33
Message-ID: 19821.12117.630296.800838@io.astro.umass.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse psycopg by date

  From Date Subject
Next Message Daniele Varrazzo 2011-03-01 22:56:58 Re: gmpy adapter
Previous Message Daniele Varrazzo 2011-03-01 17:19:29 Re: gmpy adapter