ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Some situation, involved calculation that is very large where you must allowcate some bits of memory to be larger than the standard type that C has.
So i want to know "How can I declare new type (for my arbitrary numbers of bits, says 1024 bits or something)?".
excel28, thanks for pointing me to the right source BUT i am not yet know the answer.
I am now looking at BIGNUM structure (BIGNUM is name for bignum_st, real structure) in include/bn.h.
It defined as follow,
Code:
struct bignum_st
{
BN_ULONG *d; /* Pointer to an array of 'BN_BITS2' bit chunks. */
int top; /* Index of last used d +1. */
/* The next are internal book keeping for bn_expand. */
int dmax; /* Size of the d array. */
int neg; /* one if the number is negative */
int flags;
};
Also I see from the comment that lead to bn_expand in the same file, but now I just trying to look at it.
Well C can only store data types that are big enough to be stored into a register on the computer so in essence you can only have one large enough to fit into one of them. Of course this is not a limitation as you can do some "magic" and get larger numbers to fit. I think the largest you can have is a unsigned long.
As you can see from the OpenSSL source, arbitrary precision calculations in C are highly non-trivial. Fortunately, there are libraries to ease this task, for example GMP.
Well, if it makes things a little more clear: In general, all of the arithmetic operations performed on built-in types are defined in asm, and therefore directly correlate to single processor operations. To go outside of those boundaries requires functions written in terms of operations on built-in types. Would you know how to calculate 1234 / 4321 not allowing any portion of the calculation to exceed 2 digits? I have no idea how to do that. Ever wonder why it takes forever to make extremely accurate scientific calculations? I think GMP is your best bet as psisquare said.
ta0kira
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.