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

  • From: Joseph Groover <looncraz@xxxxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Sun, 04 Dec 2011 20:48:37 -0600

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* :-)

I'm hoping I'm not entirely off-base (haven't read the entire discussion), but if you are trying to get an integer approximation of rounding you generally just add 0.5 to the float then cast to int...

float anonFloat = 0.83333;
int lazyRoundInt = (anonFloat+0.5);
lazyRoundInt now holds the value of 1.

I'm assuming I'm off-base, but oftentimes the simple solutions are the hardest to remember...

--The loon

Other related posts: