[haiku-development] Re: gcc enable _Decimal32, _Deimal64 and _Decimal128 (and g++ decimal32, ...) support

  • From: "Adrien Destugues" <pulkomandy@xxxxxxxxxxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Sun, 04 Dec 2011 14:18:34 +0100

> Mmmh yes, I suppose I've done the wrong example, but if you do for
> example
> a lot of calculation on double number (for example representing €/$)
> for
> example multiplying them for 5, and for 6 and in the end you want
> convert
> in €cent (casting to int multipying for 100.00)... well it can be in
> the
> end you expect 1 €/$ and get 0 €/$ as in the memory it was really a
> 0.999999999999999748 and not 1.0 (!)... I know I can round but why I
> have
> to? For me, a human being, it should do 1 not a 0, it's unimportant
> if
> CPU's likes binaries...
> I've 10 digits to use, I'm* not an horse* :-)

You're doing things in fixed precision, so you should't use floats or
Do all your math using cents, then *divide* by 100 in the end to get a
value in euros, dollars, or whatever. This way there will be no
rounding error.

It's easy enough in C++ to write some support classes for your own
software if you need to do this a lot. I see no need for doing it at
compiler level.


Other related posts: