pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Christopher Browne <cbbrowne@libertyrms.info>
To: pgsql-sql@postgresql.org
Subject: Re: numeric and float converts to int differently?
Date: Tue, 28 Oct 2003 18:11:13 -0500
Message-ID: <60u15tklf2.fsf@dev6.int.libertyrms.info> (raw)
References: <072c01c39d65$65f83950$0403a8c0@fejleszt4>
	<20031028154536.GA29427@it.is.rice.edu>
	<074b01c39d72$6f512f90$0403a8c0@fejleszt4>
	<87brs1gr4y.fsf@stark.dyndns.tv>
	<0acb01c39d90$6d9d9080$0403a8c0@fejleszt4>

surrano@mailbox.hu (SZUCS Gábor) writes:
> As Tom pointed out, it isn't a floating point failure -- it is how rounding
> float is implemented. I assume anything with less than 15 digits can be
> exactly represented as float.

No, "decimal" fractions cannot ever be exactly represented in floating
point because since they use powers of two, you wind up with repeated
fractions.

1/3 is approximately 0.3333333, but you cannot present that exactly in
decimal.

In the very same way, 1/10 is approximately equal to
0.001001001001001001001001001001 (as a binary 'fraction'); the '001'
part is a repeating group, and wherever you terminate it, you lose
exactness.
-- 
(reverse (concatenate 'string "ofni.smrytrebil" "@" "enworbbc"))
<http://dev6.int.libertyrms.com/;
Christopher Browne
(416) 646 3304 x124 (land)



view thread (7+ messages)

Message-ID: <60u15tklf2.fsf@dev6.int.libertyrms.info>
Permalink:  ../60u15tklf2.fsf@dev6.int.libertyrms.info/
Also on:    postgresql.org/message-id/60u15tklf2.fsf@dev6.int.libertyrms.info

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: cbbrowne@libertyrms.info
  Subject: Re: numeric and float converts to int differently?
  In-Reply-To: <60u15tklf2.fsf@dev6.int.libertyrms.info>

* 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