Number of bits (field in general) required to store decimal number
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.
yes.
Thank you for introducing new library function floor().But in my case I need to use ceil() as to round up value.
Actually I thought that this formula(log n/log 2) fails after certain number. But I will stick with this.
Thank you for pointing out my faults.
Anyways, let's try something to encode positive integers with bitvectors. Well, every positive integer can be written in binary, and the first binary digit is always 'one'. Let's store every bits, except for the first one:
(1) There are several well-known floating point number formats. All of them store an exponent and a mantissa. The actual number of "digits" represented internally is reflected in the mantissa, which is then raised to the power of the exponent. Probably the most-common format is the Extended floating-point type of the now-ubiquitous Intel® microprocessors.
(2) Each time you see a floating-point number, it has been converted to a printable (decimal) representation ... which, as it happens, is not exactly equal to its float-binary (internal) representation. Thus, "5.12" might be displayed as "5.1" or "5." and in any case it probably is not exactly-equal to "5.1200000...".
(3) Determination of "how many digits of the answer are significant" is really a basic engineering question, and would be even if you were using a slide-rule. Functions such as ln() are, after a certain point, just estimations. There's a certain, predictable amount of numeric error, and the subsequent series of operations that you perform will increase (never "decrease") that accumulated error.
(4) "Truly-decimal" floating point packages do exist ... which represent the numbers in question as individual digits and perform math exactly the way that you'd do it by hand. But these are typically used for accounting, not engineering applications, and I would not expect any of them to include transcendantal functions.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.