float equality
Jonathan M Davis
jmdavisProg at gmx.com
Mon Feb 21 16:57:58 PST 2011
On Monday 21 February 2011 15:58:03 Andrei Alexandrescu wrote:
> On 2/21/11 4:48 AM, Jonathan M Davis wrote:
> > On Monday 21 February 2011 01:55:28 Walter Bright wrote:
> >> Kevin Bealer wrote:
> >>> 1. To solve the basic problem the original poster was asking -- if you
> >>> are working with simple decimals and arithmetic you can get completely
> >>> accurate representations this way. For some cases like simple
> >>> financial work this might work really well. e.g. where float would not
> >>> be because of the slow leak of information with each operation. (I
> >>> assume real professional financial work is already done using a
> >>> (better)
> >>> representation.)
> >>
> >> A reasonable way to do financial work is to use longs to represent
> >> pennies. After all, you don't have fractional cents in your accounts.
> >>
> >> Using floating point to represent money is a disaster in the making.
> >
> > Actually, depending on what you're doing, I'm not sure that you can
> > legally represent money with floating point values. As I understand it,
> > there are definite restrictions on banking software and the like with
> > regards to that sort of thing (though I don't know exactly what they
> > are).
>
> This is a long-standing myth. I worked on Wall Street and have friends
> who have been doing it for years. Everybody uses double.
Hmm. Good to know. I do find that a bit scary though. I wonder what the level of
error is in doing that and how much it affects your typical monetary calculation.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list