开发者

Creating a numerical data type exceeding its normal size

There is a calculator program that I have came across on Windows long ago. I couldn't recall its name, but one impressive thing about it is that it can calculate numbers up to 512 bytes size. Requesting a pi value, for instance, it can give out numbers with hundreds of digits. (but of course it takes a few seconds to output) Normally, an int would be 4 bytes, double 8 bytes, etc.

Now, how can we do that? How can we allocate a variable for numbers that can exceed the normal range? (as in, int is 4 bytes, long is 8 bytes) And how to prevent overflow and underflow in this case? Assume that this is开发者_开发百科 C++.


Google around for the terms arbitrary-precision arithmetic and multiple-precision arithmetic. The number of libraries plus the number of applications which implement such arithmetic probably exceeds 2^32.


You can do this using the GNU MP library, or one of its competitors.

You can also roll your own, if you're good at maths.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜