which data type should i use to store a value of say (2^32)*(3^32)..
unsigned long doent work..
or is there any other way...like a special function or something?
thanks for reading!
Four answers:
Mantrid
2009-05-19 10:51:20 UTC
If an int, you need an __int64. Microsoft don't define this type, in other compilers it's in stdint.h. This is not supported on 32-bit platforms, because the C++ specs say that you only need to support int types that are supported internally by the CPU (argh!)
For compiler independent int64 on 64-bit systems, you can use this code-
#ifdef _MSC_VER
typedef __int64 int64_t // microsoft don't like standards!
#else
#include
#endif
If you need a floating point representation, "double" is a 64-bit floating point type. You will lose precision here with huge numbers because they only work to so many decimal places, so you might get rounding errors (see the IEEE 64-bit float spec for details)
Your final choice for huge numbers is to define your own special class which allows any size of int, and write your own operators for this class. This would be a lot slower than using internal types, and it would be a pretty tough job (sounds like fun though!)
There's probably free libraries with a class which allows arbitrary sized ints. I don't know any myself though.
edit: how do I create my own type?
LIke so:
class ExtraLongInteger
{
// hold data
private:
unsigned long int *Data;
unsigned int Size;
public:
// constructor
ExtraLongInteger(unsigned int size) : Data(0), Size(size)
/* and so on, overload every operator for every data type. */
};
==========
Hawt, apfloat looks interesting but the license terms are restrictive, it is incompatible with both free software (open source licenses) and commercial software. It is only useful for freeware.
Jeremy T
2009-05-19 10:41:44 UTC
I think you may have to build your own data type for that. The largest data type i could find was long long with is only 19 digits long. Yours in twenty.
another options is to look for library with integers longer then 64 bits.
lemoi
2016-11-09 12:10:49 UTC
i've got not programmed in c/c++ later on yet i think of that __int8 is used internally.. for 8 bit information. why do you ought to use an * bit quantity, purely use the int usual information sort. in case you incredibly sense you ought to use an 8 bit information sort, you ought to use char and sort solid/ rigidity it to artwork as a quantity instead of a character.. like this char x; x = 'a' ; // set as a character cout << x << endl; cout << int(x) << endl; this is considered unfavourable programming prepare, and probobly will create compiler warnings however.
2009-05-20 02:26:51 UTC
Hm....
Hawt, correct!
Have u learn abut Numeric analitic?
If we just have 16bit register, how many floating point we use to count 128bit?
Yes 8 point of register.
Schema :reg4[:reg3[:reg1[:reg1]]].
Its vector!
How to use it!
Learn Numeric Analitic!
ⓘ
This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.