Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any "type" on Borland C++ Builder like "decimal" from C#?

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?

like image 442
kokbira Avatar asked Jun 19 '12 23:06

kokbira


3 Answers

The decimal type in C#, .NET's System.Decimal type, is just a floating point number stored as base-10 instead of base-2 encoding. float and double are more typical base-2 floating point numbers. That is, a double is stored as +/- x * 2^y while 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 of x * 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::decimal namespace, and are called std::decimal::decimal32 and std::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 for IEEE 754 Decimal should turn up others if, for some reason, you need them.

like image 198
Michael Edenfield Avatar answered Oct 30 '22 04:10

Michael Edenfield


These are the float types that you can use in Delphi:

single  :  4 bytes (32bits)
real    :  6 bytes (48bits)
double  :  8 bytes (64bits)
currency:  8 bytes (64bits) (this is probably what you're looking for)
extended: 10 bytes (80bits) (maps to double when you compile to x64!)

In C++ builder there seems to be a System::Currency class that mimics Delphi's built in currency type. Maybe it helps to look into that.

like image 37
Wouter van Nifterick Avatar answered Oct 30 '22 04:10

Wouter van Nifterick


I found this link Borland C++ Primitive Data types . View it in HTML.

There is a long double type having capacity of 10 bytes.

The document is informative. You may want to read it anyway.

like image 20
The Original Android Avatar answered Oct 30 '22 05:10

The Original Android