Re: somebody could explain this?

Поиск
Список
Период
Сортировка
От Martijn van Oosterhout
Тема Re: somebody could explain this?
Дата
Msg-id 20051104164542.GC13966@svana.org
обсуждение исходный текст
Ответ на somebody could explain this?  ("Cristian Prieto" <cristian@clickdiario.com>)
Ответы Re: [OT] somebody could explain this?  (Csaba Nagy <nagy@ecircle-ag.com>)
Re: somebody could explain this?  ("Otto Hirr" <otto.hirr@olabinc.com>)
Список pgsql-hackers
On Fri, Nov 04, 2005 at 10:16:50AM -0600, Cristian Prieto wrote:
> Hello, I'm using PostgreSQL 8.0.4 in Fedora Core 3, right now I'm learning a
> little about the postgresql internals and the way some kind of SPs could be
> written in c language; I found something really weird and I cannot explain
> to me this behavior:

What's happening here is that the multiplication, being floating point,
has some accumulated error such that when you multiply it by 100 and
convert it to an int, it hits the cutoff.

Note: converting a float to an int tends to invoke trunc() or something
similar. trunc(14.999999999999) = 14. You need to decide whether maybe
you want round() instead. Or decide the actual cutoff yourself. I
sometimes fix this by adding 0.00001 to numbers before converting to
integer, to avoid these issues.

Floating points numbers are accurate but not precise.

Hope this helps,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Andrew Dunstan
Дата:
Сообщение: Re: postgresql-8.1RC1 on Solaris 10, amd64x2
Следующее
От: Andrew Dunstan
Дата:
Сообщение: Re: somebody could explain this?