In C#, there is a type called decimal (the System.Decimal structure). I have found information that shows how it is better than float and double types for some cases:
- StackOverflow – double-precision-problems-on-net
- StackOverflow – how-to-make-doubles-work-properly-c-sharp
Is there any similar type for Borland C++ Builder programs?
The
decimaltype in C#, .NET’sSystem.Decimaltype, is just a floating point number stored as base-10 instead of base-2 encoding.floatanddoubleare more typical base-2 floating point numbers. That is, adoubleis stored as+/- x * 2^ywhile a decimal is stored as+/- x * 10 ^ y. That’s why it does better for, as one example, financial data, which is typically expressed in terms ofx * 10^-2. The IEEE standard 754 (the floating point math standard) calls this “decimal floating point” math, and defines a 32- and 64-bit version of each.In C++, these types are implemented in the
std::decimalnamespace, and are calledstd::decimal::decimal32andstd::decimal::decimal64, in the<decimal>header. If Borland C++ builder has such a type, you will find it there. GNU’s C++ library includes this header but, AFAIK it’s not actually part of the standard yet, so BCB may not have it. If that’s the case, you’ll need to use a third-party library. @dash’s example of Intel’s Decimal Floating Point library is probably the best known such library, though a Google search forIEEE 754 Decimalshould turn up others if, for some reason, you need them.