Classic behaviour, which has nothing to do with postgres. Try the
program below to see the same effect. You probably should be using a
rounding function to see what you seem to expect.
cheers
andrew
#include stdio.h
main()
{
double x[] = { 0.1, 0.11, 0.12, 0.13, 0.14, 0.15 };
int i,n;
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
Cristian Prieto [EMAIL PROTECTED] writes:
Datum
repeat_item(PG_FUNCTION_ARGS)
{
int num_times;
num_times = PG_GETARG_FLOAT8(0) * 100;
PG_RETURN_INT32(num_times);
}
# Create or replace function test(float) returns integer as 'test.so'
language 'c' stable;
float
Cristian,
I bet it's related to some rounding issue and the fact that floating
formats are approximative even for small integers.
Probably 12 ands up being slightly less in floating format (something
like 11.999...), and the cast to integer is truncating it.
Not 100% sure though... read up on
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.
Trivia...
I heard a story many years ago that landed a programmer in prison...
He worked on the program that
Otto Hirr [EMAIL PROTECTED] writes:
Trivia...
I heard a story many years ago that landed a programmer in prison...
He worked on the program that calculated interest that was to be
deposited into an account. Instead of rounding or truncating the
amount beyond what the bank wanted to use, he