Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kUxnq-0003pA-TV for pgsql-jdbc@arkaria.postgresql.org; Tue, 20 Oct 2020 20:00:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kUxnp-0000Rf-TS for pgsql-jdbc@arkaria.postgresql.org; Tue, 20 Oct 2020 20:00:13 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kUwwI-0002Yy-Aa for pgsql-jdbc@lists.postgresql.org; Tue, 20 Oct 2020 19:04:54 +0000 Received: from mail-lj1-x236.google.com ([2a00:1450:4864:20::236]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kUwwF-0003wJ-QY for pgsql-jdbc@lists.postgresql.org; Tue, 20 Oct 2020 19:04:53 +0000 Received: by mail-lj1-x236.google.com with SMTP id c21so3166413ljn.13 for ; Tue, 20 Oct 2020 12:04:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=5qO8YmKhl9CAy8WFX4qP1YSjePDmAkxO3leU5pZeTYg=; b=ikUSNoJsq1Z4Y+ndHOr7Bc98DHTBiiMWxGSmYxUGIx1Q5LU0qx3jXrae89FU6EK0ih EdsWi+4/aCAwZCZFkfMdH81e59zqw8FAbvUF89vlRA2jNj00/7esA5GMg0yKJY6lGR05 i3JA80VPQGBE+qSDh+CNof/9H3qTZBO6wvd369TRGD2ZaTjKqJ6r7SlQXGUpaDH+b5DS 4jpIxcHSRDcj5Z7asjCa2qza8gy9qLocVM2fTx0kio6f2bAr5LQ0SQv/i9eoFWyC612Y FeYl5EYCevzm0pqeiEnhSMuGiQPfkn1kgd9YeKt/9o4Zl9rQQrxH5V12UE9aHZeTPqjK ROpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=5qO8YmKhl9CAy8WFX4qP1YSjePDmAkxO3leU5pZeTYg=; b=qCx/Qd3GANECpjtYDRCxMivIncPijERc3UQcFR94ZQ3dAwZRHJfFqWgMHm62fbx2ht yFS7M0buame1Gq3Fc2cPc2Zix2BG2s8ThdnMmYsdpmlpYvPgnn8dbUarCuhw2C3ND2fT BFV34gMzJKqHOgn2+xICO1EmPQ3+++RWaNz/nqkopq4gJJ2g+MAaVv9M1aXqsGv/ySZv dywRzU+Z+4LW1hmXpV6vuoYruDWeF49SCbCE8VQUcs7APx3t6D1oiergxzbZ9+ahni2p THTLCSN5vdUYp+6w4zDtR6a/ew3vWcEHVKWTwvYYCwtk/f57/e+9vicZmepmFyEy/aRl rozg== X-Gm-Message-State: AOAM532KlV+U5LcCUZsASsR9EyKAirYROud/k+FYKluPvsOqsqCW36qS LS5qbjpVRa4FrZX7zao1iSTPzguj4ak= X-Google-Smtp-Source: ABdhPJyJLtEf0tGxwMc+xZqNyPmzDJrPKC8ziUsqZxlTaJb1eLq4Ce9007Mf5YUx8edpbNEaORNswA== X-Received: by 2002:a05:651c:102a:: with SMTP id w10mr1670769ljm.64.1603220689180; Tue, 20 Oct 2020 12:04:49 -0700 (PDT) Received: from [192.168.0.155] (31-208-42-197.cust.bredband2.com. [31.208.42.197]) by smtp.gmail.com with ESMTPSA id u28sm434245lfi.182.2020.10.20.12.04.48 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 20 Oct 2020 12:04:48 -0700 (PDT) Subject: Re: PostgresSQL 10 | Driver 42.2.5 | Float Conversion Issue To: pgsql-jdbc@lists.postgresql.org References: <652597.1603214274@sss.pgh.pa.us> From: Mikael Message-ID: <8dc8b2f8-5a08-32e4-9bf7-30673ffe4637@gmail.com> Date: Tue, 20 Oct 2020 21:04:49 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.3.3 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------FEE2026CB65C0E8137DA46FF" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------FEE2026CB65C0E8137DA46FF Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit 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 > >: > > Andreas Joseph Krogh 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 > www.visena.com > --------------FEE2026CB65C0E8137DA46FF Content-Type: multipart/related; boundary="------------E412DF368941655C089B2EAA" --------------E412DF368941655C089B2EAA Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

Well, the documentation say:

"The data types real and double precision are inexact, variable-precision numeric types. In practice, these types are usually implementations of IEEE Standard 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>:
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
 
--------------E412DF368941655C089B2EAA Content-Type: image/png; name="mghchhkpdljkedfl.png" Content-Transfer-Encoding: base64 Content-ID: Content-Disposition: inline; filename="mghchhkpdljkedfl.png" iVBORw0KGgoAAAANSUhEUgAAAIUAAAAYCAYAAADUIj6hAAAABHNCSVQICAgIfAhkiAAABzBJ REFUaEPtmNFxHDcMhmVP3i1VECpvnjzkVIHWFfhcgVcVRKrAUgWRK/C6Al8H3lTgy0PGbzFd Qc4VJP/HADs43q6kROeJNbOYgQACIAgCWJKng4MZ5gxUGXh0U0b+SIuF9G+EWXj2Q15vbrE/ NPtk9uub7Gfdt5mBx1NhqSEo8HshjbEUtlO2yIM9tsx5dZP9rPt2MzDZFAqZE4LGcFjdsg3s aQaHt7fY70X949OnaS+OZidDBkavD33157L4xaw2os+Mp/DAC10l2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