Hi
can I use "decimal"(C#128bit type) type also in C++,maybe with some custom library for it?
Printable View
Hi
can I use "decimal"(C#128bit type) type also in C++,maybe with some custom library for it?
long double tends to be 96 bit type; I suggest you try it and see how long it is.
Tim S.
From: Types - C# language specification | Microsoft Docs
Quote:
The decimal type
The decimal type is a 128-bit data type suitable for financial and monetary calculations. The decimal type can represent values ranging from 1.0 * 10^-28 to approximately 7.9 * 10^28 with 28-29 significant digits.
The finite set of values of type decimal are of the form (-1)^s * c * 10^-e, where the sign s is 0 or 1, the coefficient c is given by 0 <= *c* < 2^96, and the scale e is such that 0 <= e <= 28.The decimal type does not support signed zeros, infinities, or NaN's. A decimal is represented as a 96-bit integer scaled by a power of ten. For decimals with an absolute value less than 1.0m, the value is exact to the 28th decimal place, but no further. For decimals with an absolute value greater than or equal to 1.0m, the value is exact to 28 or 29 digits. Contrary to the float and double data types, decimal fractional numbers such as 0.1 can be represented exactly in the decimal representation. In the float and double representations, such numbers are often infinite fractions, making those representations more prone to round-off errors.
> can I use "decimal"(C#128bit type) type also in C++,maybe with some custom library for it?
If only someone had invented a way to search the web for things....
May be this source could be useful:
This lines are not shown by my post, no matter why:Code:#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <float.h>
int main(int argc, char** argv) {
//printf("CHAR_BIT : %d\n", CHAR_BIT);
printf("\nLength of Data typs\nand their limits of Valuews\n\n");
printf("char.......: %ld Byte in Bit: %d\n", sizeof(char), CHAR_BIT);
printf("signed char...: %d to %d\n", CHAR_MAX, CHAR_MIN);
printf("unsigned char.: 0 to %d\n\n", UCHAR_MAX);
//printf("SCHAR_MAX : %d\n", SCHAR_MAX);
//printf("SCHAR_MIN : %d\n", SCHAR_MIN);
printf("short.......: %ld Byte\n", sizeof(short));
printf("SHRT_MAX : %d\n", SHRT_MAX);
printf("SHRT_MIN : %d\n", SHRT_MIN);
printf("USHRT_MAX : %d\n\n", (unsigned short) USHRT_MAX);
printf("Datentyp int %ld Byte\n", sizeof(int));
printf("INT_MAX : %d\n", INT_MAX);
printf("INT_MIN : %d\n", INT_MIN);
printf("UINT_MAX : %u\n", (unsigned int) UINT_MAX);
printf("\nlong : %ld Byte\n", sizeof(long));
printf("LONG_MAX : %ld\n", (long) LONG_MAX);
printf("LONG_MIN : %ld\n", (long) LONG_MIN);
printf("ULONG_MAX : %lu\n\n", (unsigned long) ULONG_MAX);
printf("float : %ld Byte\n", sizeof(float));
printf("FLT_MAX : ±%f\n", FLT_MAX);
printf("FLT_MAX : ±%E\n", FLT_MAX);
printf("FLT_MIN : %f\n", FLT_MIN);
printf("FLT_DIG : %d\n", FLT_DIG);
printf("\ndouble : %ld Byte\n", sizeof(double));
//printf("DBL_MAX : %lf\n", DBL_MAX);
printf("DBL_MAX : ±%lG\n", DBL_MAX);
printf("DBL_MIN : %lf\n", DBL_MIN);
printf("DBL_DIG : %d\n", FLT_DIG);
printf("\nDatentyp long double: %ld Byte\n\n", sizeof(long double));
printf("LDBL_MIN : %LG\n", LDBL_MIN);
printf("_DBL_MAX : %LG\n", LDBL_MAX);
printf("LDBL_DIG : %d\n", LDBL_DIG);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <float.h>