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:
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