On Wed, 12 Feb 2025 at 20:01, Eugene Galkin via Gcc-help <gcc-help@xxxxxxxxxxx> wrote: > > Hello gcc-help, > > I found janis187@xxxxxxxxxx address in the decimal.h header file. But that > address doesn't seem to work. Janis retired from IBM some time ago. > I have some questions about decimal floating point support in GCC which I > hope you could clarify. > > I work in a C++ financial project and we're considering switching to some > decimal floating point type. > I found there are new types decimal32, decimal64 and decimal128 along with > some related functions, mainly conversions from/to other types. > However, I didn't find any string conversions or math functions related to > these new types. I tried different ways of including system headers, like > > #define __STDC_WANT_DEC_FP__ > #include <stdlib.h> > > but this didn't work for me. Because <stdlib.h> comes from Glibc and doesn't know anything about the GCC Decimal FP extensions. If you include <float.h> and define that macro, or __STDC_WANT_IEC_60559_DFP_EXT__, or compile with -std=c23 then you'll get the decimal float support in <float.h> (because that header is provided by GCC, not Glibc). In C++ you can use #include <decimal/decimal> which is a partial implementation of ISO/IEC TR 24733. > It is stated at > https://gcc.gnu.org/onlinedocs/gcc-11.2.0/gcc/Decimal-Float.html (other GCC > versions as well) that the support is incomplete. Same seems to be true for > the latest available GCC 14.2 on godbolt. I looked through GCC release > changes at https://gcc.gnu.org/gcc-<N>/changes.html but there seems to be > little information on decimal support as well. > > 1. Could you please confirm that there is still only limited support for > these types in GCC? Or I just didn't enable it in some proper way? You don't need to do anything to enable support for _Decimal32 in the compiler. You need to #include <decimal/decimal> for C++ library support. > 2. Is there currently any way to convert decimal<N> types to/from string? See https://github.com/libdfp/libdfp which provides printf-hooks for use with Glibc. It would be good if somebody used that code to implement std::formatter specializations for std::decimal::decimal32 etc. > 3. Are you aware of when full support is going to be implemented? I don't expect anybody will do any more work on ISO/IEC TR 24732 or ISO/IEC TR 24733. I don't know the status of C23 DFP support, but that's where I would expect any future work to happen. > I did some research and found two major decimal libraries that conform to > IEEE 754-2019. > These are DecNumber from https://speleotrove.com/decimal/ and Intel Decimal > Floating Point library from https://www.netlib.org/misc/intel/ > > However, I found these libraries exist on GitHub at different places: > https://github.com/gcc-mirror/gcc/tree/master/libdecnumber vs > https://github.com/libdfp/libdfp/tree/master/libdecnumber > and > https://github.com/gcc-mirror/gcc/tree/master/libgcc/config/libbid vs > https://github.com/libdfp/libdfp/tree/master/libbid I don't think these are related to the Intel library at all, are they? > I did contact Marius Cornea from Intel, mentioned in the Intel sources, and > he confirmed netlib sources to be the primary. > At the same time GCC mirror sources have Free Software Foundation copyright > and the code has differences, which I'm not sure to be fixes or related to > some integration process. That would make sense if the GCC code is unrelated to the Intel code. > My current understanding is GCC is planning to add support for decimal > types via the mentioned two libraries. But I'm a bit lost on which part > goes where and when. I don't know anything about any such plans, maybe somebody else can answer that. > 4. Could you please clarify on how these libraries are related and which > source is a better choice if I decide to use one or another as a standalone > library for our purposes? > > Regards, > Eugene