Is it possible to make an array of doubles like a c-style string to make a bigger number? Or is an array of chars a special thing to a compiler?

Recommended Answers

All 4 Replies

Is it possible to make an array of doubles like a c-style string to make a bigger number? Or is an array of chars a special thing to a compiler?

Do you need something like this?

char Array[100]={'1','2','3','4','.','1','2','3','4','5','6','7','8'};

If so, I could help, I remember I did one task "Create program for addition of two enormously big numbers", so the point was to create numbers stored into strings ( array of characters ) and make them calculable, like Array[10] + Array[10], what happens if it's bigger than 10, and stuff like that.

I ment use an actual array of double to make the number bigger.

Not as such, no. The standard formats for floating-point numbers is such that this wouldn't work. With most x86 compilers, a double is 64 bits long, with one bit for sign, 11 bits for the exponent, and 52 for the significand (that is, the value to the right of the binary point). This format is dictated by the floating-point hardware, so that alone presents a limitation on conventional floating-point numbers. To span the numbers across an array like you suggest would require the compiler to separate the different bit sections out of each number, then span them separately. This simply isn't practical, and even if it were, you would need a compiler that supported it in some fashion.

How large a number do you need? Most compilers for C (and some for C++) support the long double type, which on the x86 uses an 80 bit extended double format. This may be large enough for your purposes.

Realistically, your best solution may be to use a bignum library such a the GNU Multiprecision arithmetic library (GMP). It is widely used for such purposes, being a key component of some important programs (e.g., GCC).

OTOH, this may not be acceptable if you are working on a homework project, so it depends on what you are doing. If it is homework, and multi-precision math is the objective of the assignment, you'll have to write your own bignum code - and as I said, doubles cannot be spanned.

Another tip - that is even if long double is falling short..
U can use

signed long double

if u need only positive numbers and ur range is falling short.. What this does, is nothing but increase the range of long double by two times !!

In response to the main question - no double array cannot be used as a c string as there are no functions defined for it as defined in "string.h"(turbo c++) which is specially encoded only for char arrays. If in the future some guy makes it for double too.. We shall be blessed :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.