Re: [HACKERS] IEEE 754

Lists: pgsql-adminpgsql-hackers
From: Sai Hertz And Control Systems <sank89(at)sancharnet(dot)in>
To: pgsql-admin(at)postgresql(dot)org
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: IEEE 754
Date: 2003-12-29 17:28:41
Message-ID: 3FF06449.7080208@sancharnet.in
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-hackers

Dear all ,

I would like to share my concerns about the IEEE 754 specification and
floating point handling by PostgreSQL .

Also I would like to learn how professional users of PostgreSQL work
with rounding of monetary terms .

If you would like to know whats IEEE 754 read this
http://docs.sun.com/source/806-3568/ncg_goldberg.html

Regards,
Vishal Kashyap.


From: Jan Wieck <JanWieck(at)Yahoo(dot)com>
To: aspire420(at)hotpop(dot)com
Cc: pgsql-admin(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [HACKERS] IEEE 754
Date: 2003-12-29 19:13:45
Message-ID: 3FF07CE9.5070707@Yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-hackers

Sai Hertz And Control Systems wrote:

> Dear all ,
>
> I would like to share my concerns about the IEEE 754 specification and
> floating point handling by PostgreSQL .
>
> Also I would like to learn how professional users of PostgreSQL work
> with rounding of monetary terms .

For all monetary values the PostgreSQL datatype NUMERIC should be used.
It is a builtin datatype using arbitrary precision math.

Jan

>
> If you would like to know whats IEEE 754 read this
> http://docs.sun.com/source/806-3568/ncg_goldberg.html
>
>
> Regards,
> Vishal Kashyap.
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly

--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #


From: Mike Mascari <mascarm(at)mascari(dot)com>
To: aspire420(at)hotpop(dot)com
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: IEEE 754
Date: 2003-12-29 19:27:46
Message-ID: 3FF08032.4050403@mascari.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-hackers

Sai Hertz And Control Systems wrote:

> Dear all ,
>
> I would like to share my concerns about the IEEE 754 specification and
> floating point handling by PostgreSQL .
>
> Also I would like to learn how professional users of PostgreSQL work
> with rounding of monetary terms .
>
> If you would like to know whats IEEE 754 read this
> http://docs.sun.com/source/806-3568/ncg_goldberg.html

No sane human being would use floating point for monetary values.
NUMERIC is an arbitrary precision type capable of effectively limitless
scale and precision, although it is currently defined as having a limit
of 1000:

#define NUMERIC_MAX_PRECISION 1000

As far as rounding is concerned, it depends on the application. For
example, in the United States at least, each state has devised their own
rounding rules with respect to sales and use taxes. For a look at how
very bad sausage is made:

http://www.ecommercetax.com/official_docs/SSTP%20-%20Rounding.pdf

Mike Mascari
mascarm(at)mascari(dot)com


From: Michael Glaesemann <grzm(at)myrealbox(dot)com>
To: aspire420(at)hotpop(dot)com
Cc: pgsql-admin(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [HACKERS] IEEE 754
Date: 2003-12-29 20:29:31
Message-ID: B54ECD34-3A3D-11D8-BE84-000A95C88220@myrealbox.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-hackers


On Dec 29, 2003, at 11:28 AM, Sai Hertz And Control Systems wrote:
> I would like to share my concerns about the IEEE 754 specification and
> floating point handling by PostgreSQL .

What specifically are your concerns regarding floating point handling
and PostgreSQL? I'm not in a position to address your concerns, but I
would like to know what they are.

Michael Glaesemann
grzm myrealbox com


From: William Yu <wyu(at)talisys(dot)com>
To: pgsql-admin(at)postgresql(dot)org
Subject: Re: IEEE 754
Date: 2003-12-29 22:36:19
Message-ID: bsqa90$10l8$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-hackers

The answer is simple. Don't use floating point for money.

Sai Hertz And Control Systems wrote:
> Dear all ,
>
> I would like to share my concerns about the IEEE 754 specification and
> floating point handling by PostgreSQL .
>
> Also I would like to learn how professional users of PostgreSQL work
> with rounding of monetary terms .
>
> If you would like to know whats IEEE 754 read this
> http://docs.sun.com/source/806-3568/ncg_goldberg.html
>
>
> Regards,
> Vishal Kashyap.
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org
>


From: Toni Schlichting <toni(at)schlichting(dot)net>
To: aspire420(at)hotpop(dot)com
Cc: pgsql-admin(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: IEEE 754
Date: 2003-12-31 16:06:44
Message-ID: 3FF2F414.1070608@schlichting.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-hackers

Hi Vishal,

usage of floating poing arithmetic is a taboo in financial calculations.
This what the decimal type has been created for. Never ever use float.

Ciao, Toni

Sai Hertz And Control Systems wrote:

> Dear all ,
>
> I would like to share my concerns about the IEEE 754 specification and
> floating point handling by PostgreSQL .
>
> Also I would like to learn how professional users of PostgreSQL work
> with rounding of monetary terms .
>
> If you would like to know whats IEEE 754 read this
> http://docs.sun.com/source/806-3568/ncg_goldberg.html
>
>
> Regards,
> Vishal Kashyap.
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org
>
>


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Michael Glaesemann <grzm(at)myrealbox(dot)com>
Cc: aspire420(at)hotpop(dot)com, pgsql-admin(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [HACKERS] IEEE 754
Date: 2004-01-05 00:51:13
Message-ID: 200401050051.i050pDF22348@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-hackers

Michael Glaesemann wrote:
>
> On Dec 29, 2003, at 11:28 AM, Sai Hertz And Control Systems wrote:
> > I would like to share my concerns about the IEEE 754 specification and
> > floating point handling by PostgreSQL .
>
> What specifically are your concerns regarding floating point handling
> and PostgreSQL? I'm not in a position to address your concerns, but I
> would like to know what they are.

Floating point math itself is not precise, but rather an approximation,
usually of 8 or 14 digits. You can't approximate money. This isn't a
PostgreSQL issue but rather a general programming issue.

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073


From: Michael Glaesemann <grzm(at)myrealbox(dot)com>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: pgsql-admin(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org, aspire420(at)hotpop(dot)com
Subject: Re: [HACKERS] IEEE 754
Date: 2004-01-05 06:01:04
Message-ID: 8C33EA12-3F44-11D8-BA4F-000A95C88220@myrealbox.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-hackers


On Jan 4, 2004, at 6:51 PM, Bruce Momjian wrote:

> Michael Glaesemann wrote:
>>
>> On Dec 29, 2003, at 11:28 AM, Sai Hertz And Control Systems wrote:
>>> I would like to share my concerns about the IEEE 754 specification
>>> and
>>> floating point handling by PostgreSQL .
>>
>> What specifically are your concerns regarding floating point handling
>> and PostgreSQL? I'm not in a position to address your concerns, but I
>> would like to know what they are.
>
> Floating point math itself is not precise, but rather an approximation,
> usually of 8 or 14 digits. You can't approximate money. This isn't a
> PostgreSQL issue but rather a general programming issue.

Thanks, Bruce. I assume the arbitrary precision arithmetic Jan
mentioned which is used for the NUMERIC type takes care of this.

Michael Glaesemann
grzm myrealbox com


From: Jan Wieck <JanWieck(at)Yahoo(dot)com>
To: Michael Glaesemann <grzm(at)myrealbox(dot)com>
Cc: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, pgsql-admin(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org, aspire420(at)hotpop(dot)com
Subject: Re: [HACKERS] IEEE 754
Date: 2004-01-12 14:38:11
Message-ID: 4002B153.7030705@Yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-hackers

Michael Glaesemann wrote:
> On Jan 4, 2004, at 6:51 PM, Bruce Momjian wrote:
>
>> Michael Glaesemann wrote:
>>>
>>> On Dec 29, 2003, at 11:28 AM, Sai Hertz And Control Systems wrote:
>>>> I would like to share my concerns about the IEEE 754 specification
>>>> and
>>>> floating point handling by PostgreSQL .
>>>
>>> What specifically are your concerns regarding floating point handling
>>> and PostgreSQL? I'm not in a position to address your concerns, but I
>>> would like to know what they are.
>>
>> Floating point math itself is not precise, but rather an approximation,
>> usually of 8 or 14 digits. You can't approximate money. This isn't a
>> PostgreSQL issue but rather a general programming issue.
>
> Thanks, Bruce. I assume the arbitrary precision arithmetic Jan
> mentioned which is used for the NUMERIC type takes care of this.

That was the whole intention. Although Bruce is wrong, since most of the
time money is approximated. It is only in "bookkeeping" where this is
not allowed.

Jan

--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #


From: Sai Hertz And Control Systems <sank89(at)sancharnet(dot)in>
To: Jan Wieck <JanWieck(at)Yahoo(dot)com>
Cc: Michael Glaesemann <grzm(at)myrealbox(dot)com>, Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, pgsql-admin(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [HACKERS] IEEE 754
Date: 2004-01-12 16:36:14
Message-ID: 4002CCFE.7090402@sancharnet.in
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-hackers

Dear Jan Wieck ,

>>> Floating point math itself is not precise, but rather an approximation,
>>> usually of 8 or 14 digits. You can't approximate money. This isn't a
>>> PostgreSQL issue but rather a general programming issue.
>>
>>
>> Thanks, Bruce. I assume the arbitrary precision arithmetic Jan
>> mentioned which is used for the NUMERIC type takes care of this.
>
>
> That was the whole intention. Although Bruce is wrong, since most of
> the time money is approximated. It is only in "bookkeeping" where this
> is not allowed.

Yes I agree with you Jan , most of the time we round the amount and
this is done by truncating greater than 3 decimal digits and rounding
the 3 digit to 2 in other words :
select trunc(1000.236897,3);
then
selecr round(1000.236,2);
This takes care of the rounding factor in money as per Indian standards
ok, how will you verify it simple just use log and you will get the
correct output.

Regards,
Vishal Kashyap


From: Jan Wieck <JanWieck(at)Yahoo(dot)com>
To: aspire420(at)hotpop(dot)com
Cc: Michael Glaesemann <grzm(at)myrealbox(dot)com>, Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, pgsql-admin(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [HACKERS] IEEE 754
Date: 2004-01-12 16:45:17
Message-ID: 4002CF1D.3030406@Yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-hackers

Sai Hertz And Control Systems wrote:

> Dear Jan Wieck ,
>
>>>> Floating point math itself is not precise, but rather an approximation,
>>>> usually of 8 or 14 digits. You can't approximate money. This isn't a
>>>> PostgreSQL issue but rather a general programming issue.
>>>
>>>
>>> Thanks, Bruce. I assume the arbitrary precision arithmetic Jan
>>> mentioned which is used for the NUMERIC type takes care of this.
>>
>>
>> That was the whole intention. Although Bruce is wrong, since most of
>> the time money is approximated. It is only in "bookkeeping" where this
>> is not allowed.
>
> Yes I agree with you Jan , most of the time we round the amount and
> this is done by truncating greater than 3 decimal digits and rounding
> the 3 digit to 2 in other words :
> select trunc(1000.236897,3);
> then
> selecr round(1000.236,2);
> This takes care of the rounding factor in money as per Indian standards
> ok, how will you verify it simple just use log and you will get the
> correct output.

What most people do not understand is the fact that real bookkeeping
only uses the 4 basic mathematical operators, and multiplication and
division even only when dealing with interest-, customs- or tax-rates.

Everything that uses any higher functions like power, logarithms and the
like is controlling and financial anlysis, maybe using accounting data,
but never feeding anything back into the bookkeeping.

People are often under the impression that effective APR's and all that
stuff fall into the same category as your bank or credit card account
balance. But that is not true.

Jan

--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #


From: Jan Wieck <JanWieck(at)Yahoo(dot)com>
To: aspire420(at)hotpop(dot)com
Cc: Michael Glaesemann <grzm(at)myrealbox(dot)com>, Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, pgsql-admin(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [HACKERS] IEEE 754
Date: 2004-01-12 17:12:40
Message-ID: 4002D588.4030503@Yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-hackers

Sai Hertz And Control Systems wrote:

> Dear Jan Wieck ,
>
>>>
>>> Yes I agree with you Jan , most of the time we round the amount and
>>> this is done by truncating greater than 3 decimal digits and
>>> rounding the 3 digit to 2 in other words :
>>> select trunc(1000.236897,3);
>>> then
>>> selecr round(1000.236,2);
>>> This takes care of the rounding factor in money as per Indian
>>> standards ok, how will you verify it simple just use log and you will
>>> get the correct output.
>>
>>
>> People are often under the impression that effective APR's and all
>> that stuff fall into the same category as your bank or credit card
>> account balance. But that is not true.
>
> What are you suggesting thattruncing and rounding is not good in
> financial terms

If that is what Indian accounting rules require, that is what you do.

Jan

--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #


From: Sai Hertz And Control Systems <sank89(at)sancharnet(dot)in>
To: Jan Wieck <JanWieck(at)Yahoo(dot)com>
Cc: Michael Glaesemann <grzm(at)myrealbox(dot)com>, Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, pgsql-admin(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [HACKERS] IEEE 754
Date: 2004-01-12 18:00:19
Message-ID: 4002E0B3.70607@sancharnet.in
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-hackers

Dear Jan Wieck ,

>>
>> Yes I agree with you Jan , most of the time we round the amount and
>> this is done by truncating greater than 3 decimal digits and
>> rounding the 3 digit to 2 in other words :
>> select trunc(1000.236897,3);
>> then
>> selecr round(1000.236,2);
>> This takes care of the rounding factor in money as per Indian
>> standards ok, how will you verify it simple just use log and you will
>> get the correct output.
>
>
> People are often under the impression that effective APR's and all
> that stuff fall into the same category as your bank or credit card
> account balance. But that is not true.

What are you suggesting thattruncing and rounding is not good in
financial terms

Regards,
Vishal Kashyap