Opened 8 years ago

Last modified 4 years ago

#7174 new enhancement

Decimal Floating Point support

Reported by: fano Owned by: nobody
Priority: normal Milestone: Unscheduled
Component: System/POSIX Version: R1/alpha2
Keywords: Cc:
Blocked By: Blocking:
Has a Patch: no Platform: All

Description

In these days I was working (on Linux) on an application in which I have to represent currency and seemed natural to me to use double to represent it! A great mistake now I know... double simply not work (that is I have 0.05 I multiply for 2 and obtain... 0.09 not 0.10!).

I have found that there is a new _Decimal type in the work and GCC say it is included from GCC 4.2, but sadly is not compiled by default... so in Linux it says: _Decimal32 not found! ... and I've to re-write to use integer and divide by 100 for visualization :-(

I've tried this simple C code on Haiku and it is better:

#include <stdio.h>

int 
main(void) {
    _Decimal32 d = 4.0;

     return 0;
}

GCC says: << decimal floating point not supported for this target >>

Better that Linux that says _Decimal32 not exist! But why is not supported? This support can be added? I think Decimal Floating point could be very useful if you want precise decimal calculation...

For references:

http://gcc.gnu.org/onlinedocs/gcc/Decimal-Float.html

Change History (3)

comment:1 Changed 8 years ago by fano

I've tried to recompile gcc in the Haiku svn tree adding at configure --enable-decimal-float=true and I've done make... after a lot of checking I obtain:

checking if compiler knows _Decimal64... configure: error: Compiler doesn't know _Decimal64; try GCC >= 4.2, configured with --enable-decimal-float
           
make[2]: *** [configure-stage1-mpfr] Error 1
make[2]: Leaving directory `/boot/home/Desktop/HAIKUsrc/haiku/haiku/buildtools/gcc'
make[1]: *** [stage1-bubble] Error 2
make[1]: Leaving directory `/boot/home/Desktop/HAIKUsrc/haiku/haiku/buildtools/gcc'
make: *** [all] Error 2

OK, the GCC that is compiling does not know _Decimal64, but it is for this I'm recompiling it! I do not understand to compile GCC with _Decimal64 sypport I've to use a gcc that knows of them?

Probably I'm doing something wrong... it seems a case of deadlock!

comment:2 Changed 7 years ago by fano

Adding reference to ML discussion: http://www.freelists.org/post/haiku-development/gcc-enable-Decimal32-Deimal64-and-Decimal128-and-g-decimal32-support

Summary: we should not trust GCC as a lot of time they broke backward compatibility (and in the end we hope to pass to LLVM/Clang as compiler), so maybe it's better to develop a native Haiku decimal class.

comment:3 Changed 4 years ago by pulkomandy

Milestone: R1Unscheduled
Note: See TracTickets for help on using tickets.