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

On Sun, Dec 4, 2011 at 2:14 AM, Alex Wilson <yourpalal2@xxxxxxxxx> wrote:

> On Sat, Dec 3, 2011 at 1:16 PM, fano il primo <fanoilprimo@xxxxxxxxx>wrote:
>
>> In #7174 (https://dev.haiku-os.org/ticket/7174) I've requested to add
>> decimal floating point support.
>>
>
> Thanks, a ticket is enough, and if you have more information on your
> request, please add the information there, so that anyone who is interested
> can easily find the related discussion/info all in one place. I realise
> that you haven't had any response in 10 months, but if you add a comment on
> that ticket, anyone subscribed to the tickets mailing list will get a mail
> about it.
>
> So you can add decimal floating point support? double/float are not
>> realiable for monetary calculations (let's try this: int a = (0.3 * 3  *
>> 100.00) what you get? You get not 1  but 0 (!)
>> as you get  0.999999999999999748 that trucated to an int become 0!)
>>
>
> I'm not going to comment on your request, but I can't help but be curious
> about your calculations here. In short, I don't see why you would be
> expecting to get a 1 as a result of that calculation. If you want rounding,
> then use the round() functions. Why are you storing the result of a
> floating-point calculation in an int, if the truncation is messing up your
> calculations?
>
> --Alex
>

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

Let see another example:
double a = 0.1;

if (a == 0.1)
printf("a is 0.1!\n");
else
printf("IMPOSSIBLE 0.1 != 0.1!\n"):

Compile and discover the harsh reality 0.1 != 0.1...

If 'a' it was instead declared  as a _Decimal32, in which, that is, the
floating represent a base 10 not 2, you've the result, a human being
expect... and not an horse!

There's in the GCC configure a flag: --enable-decimal-float[1] but as said
GCC not compile itself if enabled, months ago I've reached
the point that GCC compiles libdecnumber right, but in the end it says
again it not know what is "_Decimal32"???
For more info on decimal floating point:
http://gcc.gnu.org/onlinedocs/gcc/Decimal-Float.html

Bye
fano

[1] http://gcc.gnu.org/install/configure.html

Other related posts: