From: Mikael <mikael.aronsson@gmail.com>
To: pgsql-jdbc@lists.postgresql.org
Subject: Re: PostgresSQL 10 | Driver 42.2.5 | Float Conversion Issue
Date: Tue, 20 Oct 2020 21:04:49 +0200
Message-ID: <8dc8b2f8-5a08-32e4-9bf7-30673ffe4637@gmail.com> (raw)
In-Reply-To: <VisenaEmail.91.1593ba84a90d02a5.17547533c82@tc7-visena>
References: <CH2PR19MB3798B6096BD4EA60C2068367831F0@CH2PR19MB3798.namprd19.prod.outlook.com>
<VisenaEmail.9.b226ab802321bcdc.17544a6d3e3@tc7-visena>
<CH2PR19MB3798DAEA77750DD4F4CE67A0831F0@CH2PR19MB3798.namprd19.prod.outlook.com>
<VisenaEmail.e.3213a432433c7179.17544c1d629@tc7-visena>
<CAKFQuwbbYTc63HeEBPXcDzPU28Do4z+y9ZEwQKVFwCnbPP1FaQ@mail.gmail.com>
<VisenaEmail.90.b09bf69bfcec8e52.17546ec4f83@tc7-visena>
<652597.1603214274@sss.pgh.pa.us>
<VisenaEmail.91.1593ba84a90d02a5.17547533c82@tc7-visena>
Well, the documentation say:
"The data typesrealanddouble precisionare inexact, variable-precision
numeric types. In practice, these types are usually implementations
ofIEEEStandard 754 for Binary Floating-Point Arithmetic (single and
double precision, respectively), to the extent that the underlying
processor, operating system, and compiler support it.
Inexact means that some values cannot be converted exactly to the
internal format and are stored as approximations, so that storing and
retrieving a value might show slight discrepancies"
I think that counts as a big fat warning, it's the same in all SQL
servers, nothing unique for PG, the alternative is of course the NUMERIC
data type.
On 2020-10-20 20:51, Andreas Joseph Krogh wrote:
> På tirsdag 20. oktober 2020 kl. 19:17:54, skrev Tom Lane
> <tgl@sss.pgh.pa.us <mailto:tgl@sss.pgh.pa.us>>:
>
> Andreas Joseph Krogh <andreas@visena.com> writes:
> > How can this be sane?
>
> If you're expecting exact results from float calculations, you need
> a refresher course in what floating-point arithmetic is all about.
>
> From a programming perspective - yes, from a DB-client perspective,
> and in general, no way. In general - "Users" expect "reals" to be just
> "decimal-numbers", so with this behaviour of float in PG so close to
> "C-float" there should, IMO, be a big fat warning "Don't use the float
> datatype, at all" somewhere. Try to tell an accountant that doing
> calculations with floating-point numbers is crazy, and you should
> expect the computer to give you wrong answers...
> --
> *Andreas Joseph Krogh*
> CTO / Partner - Visena AS
> Mobile: +47 909 56 963
> andreas@visena.com <mailto:andreas@visena.com>
> www.visena.com <https://www.visena.com;
> <https://www.visena.com;
Attachments:mghchhkpdljkedfl.png (image/png, 1.9K) downloadview image
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: mikael.aronsson@gmail.com
Subject: Re: PostgresSQL 10 | Driver 42.2.5 | Float Conversion Issue
In-Reply-To: <8dc8b2f8-5a08-32e4-9bf7-30673ffe4637@gmail.com>
References: <CH2PR19MB3798B6096BD4EA60C2068367831F0@CH2PR19MB3798.namprd19.prod.outlook.com> <VisenaEmail.9.b226ab802321bcdc.17544a6d3e3@tc7-visena> <CH2PR19MB3798DAEA77750DD4F4CE67A0831F0@CH2PR19MB3798.namprd19.prod.outlook.com> <VisenaEmail.e.3213a432433c7179.17544c1d629@tc7-visena> <CAKFQuwbbYTc63HeEBPXcDzPU28Do4z+y9ZEwQKVFwCnbPP1FaQ@mail.gmail.com> <VisenaEmail.90.b09bf69bfcec8e52.17546ec4f83@tc7-visena> <652597.1603214274@sss.pgh.pa.us> <VisenaEmail.91.1593ba84a90d02a5.17547533c82@tc7-visena> <8dc8b2f8-5a08-32e4-9bf7-30673ffe4637@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox