(no title)
roessland | 2 years ago
select pg_typeof(9999999999999999.0);
-- numeric
select 9999999999999999.0::double precision
- 9999999999999998.0::double precision;
-- 2
More interesting perhaps, is mixing up `real` (aka float32) with `numeric`: select 9999999999999999.0::real - 9999999999999998.0;
-- 272564226 (?! can anyone explain?)
select 9999999999999999.0::real;
-- 10000000300000000
Wat
moefh|2 years ago
For some reason Postgres prints it as `10000000300000000`. It uses a heuristic to print a "pretty" number that converts to the actual stored value, and it's not smart enough to give `10000000000000000`. Some heuristic like this is needed so something like `0.3` doesn't print the actual stored value of `0.300000011920928955078125`, which would be confusing.
You can check all this here: https://www.h-schmidt.net/FloatConverter/IEEE754.html
zokier|2 years ago