:

Unsigned int full precision

Added by: ~Ramees, 2016 II 18

Added by: ~Ramees, 2016 II 18

Hi iam a beginner in c++ i am trying to create a calculator that print basic (+ - / ) only unsigned value at any big precision can any one show a sample how to create thanks in advance i compiled give examples but its only with few values i need like
Eg :- 3456778888765443222345677*22344567778998765443334566
I need this much big precision is it possible

Added by: ~Sander Bouwhuis, 2016 III 15

Yes, you certainly can. You have to define the size of the integers.
I have defined the types like this:

#ifdef _WIN64
typedef __int8 int8;
typedef __int16 int16;
typedef __int32 int32;
typedef __int64 int64;
typedef ttmath::Int< 2> int128;
typedef ttmath::Int< 4> int256;
typedef ttmath::Int< 8> int512;
typedef ttmath::Int<16> int1024;
typedef ttmath::Int<32> int2048;
typedef ttmath::Int<64> int4096;

typedef unsigned __int8 uint8;
typedef unsigned __int16 uint16;
typedef unsigned __int32 uint32;
typedef unsigned __int64 uint64;
typedef ttmath::UInt< 2> uint128;
typedef ttmath::UInt< 4> uint256;
typedef ttmath::UInt< 8> uint512;
typedef ttmath::UInt<16> uint1024;
typedef ttmath::UInt<32> uint2048;
typedef ttmath::UInt<64> uint4096;

typedef ttmath::Big<1, 1> float64;
typedef ttmath::Big<1, 2> float128;
typedef ttmath::Big<1, 4> float256;
typedef ttmath::Big<1, 8> float512;
typedef ttmath::Big<1,16> float1024;
typedef ttmath::Big<1,32> float2048;
typedef ttmath::Big<1,64> float4096;
#else
typedef __int8 int8;
typedef __int16 int16;
typedef __int32 int32;
typedef __int64 int64;
typedef ttmath::Int< 4> int128;
typedef ttmath::Int< 8> int256;
typedef ttmath::Int<16> int512;
typedef ttmath::Int<32> int1024;
typedef ttmath::Int<64> int2048;
typedef ttmath::Int<128> int4096;

typedef unsigned __int8 uint8;
typedef unsigned __int16 uint16;
typedef unsigned __int32 uint32;
typedef unsigned __int64 uint64;
typedef ttmath::UInt< 4> uint128;
typedef ttmath::UInt< 8> uint256;
typedef ttmath::UInt<16> uint512;
typedef ttmath::UInt<32> uint1024;
typedef ttmath::UInt<64> uint2048;
typedef ttmath::UInt<128> uint4096;

typedef ttmath::Big<2, 4> float128;
typedef ttmath::Big<2, 8> float256;
typedef ttmath::Big<2,16> float512;
typedef ttmath::Big<2,32> float1024;
typedef ttmath::Big<2,64> float2048;
typedef ttmath::Big<2,128> float4096;
#endif

Then, in your functions you can do something like this:
int256 MultiplyNums(int256 i256NumA, int256 i256NumB)
{
return i256NumA * i256NumB;
}

void main()
{
int256 i256NumA, i256NumB, i256Mult;

i256NumA = "-12345678901234567890";
i256NumB = "112233445566778899";
i256Mult = MultiplyNums(i256NumA, i256NumB);
}