Re: Avoiding floating points




"Jonathan Neve[Microtec]" <jonathan@xxxxxxxxxxx> wrote
I hate floating points with a passion. Does anyone
know of a simple way to get rid of them ...

Jonathan,

Cast a vote for QualityCentral report #28022 titled
"Add Fixed and Floating Decimal Point Numbers to Delphi"
http://qc.borland.com/qc/wc/qcmain.aspx?d=28022

and somehow be able to do elementary calculations
without random imprecisions and unpredictable
and meaningless error messages popping up ...

An answer to that is more difficult. Suppose that
you want to divide 4 by 3, add 0.01, and then store
the result for use later. In elementary school
arithmetic we could use fractions or mixed whole and
fraction numbers. However without round-off, it gets
a little complicated.

And if you do allow for rounding the result into a
decimal fraction result (or almost any other type of
result), then you need to specify or know what
rounding rule will be applied and particularly where
in the calculation it should be applied.

I think that an answer to a large class of such
problems is to be able to use fixed and floating
*decimal* point numbers (hence my QC suggestion).
However even this requires that *every* *divide*
operation be allowed to have a rounding specifier
to determine whether 4/3 should be stored as
1.33 or 1.34. To simplify such specifications, one of
my suggestions allows for the rounding rule to be
specified with in declaration of the decimal variables.

Until such number and operation types are available
to us, and while we struggle to get by with the
common floating *binary* point numbers, you can use
my decimal rounding package available from CodeCentral.
http://cc.codegear.com/Item.aspx?id=21909
When used properly, it can account for the small errors in
our common single, double, and extended types and can
make you think that you are working with fixed decimal
fraction numbers.

With sympathy, JohnH

--
Support the movement to add floating and fixed
decimal fraction numbers to Delphi.
http://qc.borland.com/wc/qcmain.aspx?d=28022
Quality Central, bug status & reporting http://qc.borland.com/
Code Central http://codecentral.borland.com/codecentral/ccweb.exe
.



Relevant Pages

  • Re: Currency Datatype Really Good to Use For Non-currency Fields?
    ... That means it has none of the rounding issues inherent in ... Cannot handle minute or enormous values the way floating point fields ... You need to specify the Format, so it does not display as currency. ... It seems that the currency datatype should do just fine for ...
    (microsoft.public.access.tablesdbdesign)
  • Re: decimal round off issue
    ... representation of floating point numbers. ... floating point CANNOT represent the base ten number "2.25"? ... I'm not sure that rounding happens the same way on all systems when there is ... a repeting binary fraction. ...
    (comp.lang.perl.misc)
  • Re: Why not FP for Money?
    ... I had started with the assumption that the IEEE 754 rounding methods ... accounting has rules about rounding, ... Floating point arithmetic is useful for continuous quantities, ... applies here if you are dealing with actual pennies. ...
    (comp.lang.python)
  • Re: converting float to double
    ... Although I can not see a guarantee from your floating ... rounding, it does not generalise to, e.g., ...
    (comp.lang.c)
  • Re: Bug in Delphi SimpleRoundTo function?
    ... calculations also use bankers rounding. ... rounding rule that most programmers can agree on. ... the trap of using floating *binary* point numbers, ... to represent decimal fraction ...
    (borland.public.delphi.non-technical)