Computing.Net > Forums > Programming > computing large numbers. powers of

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

computing large numbers. powers of

Reply to Message Icon

Name: Ordinus
Date: September 21, 2006 at 14:26:18 Pacific
OS: Win XP pro SP2
CPU/Ram: IBM T60
Product: IBM
Comment:

I am trying to take the digits of a large number (has a maximum of 99 digits) and re assembling them as the original number. to do this i am using the d x 10^0 + d x 10^1 + ... etc. Im using
exponent = pow(10,b) ;

but as b exeeds 9, the value of the exponent become wierd numbers. i have set exponent as double, long double, and long long int, but they all produce the same results. any ideas? thanks!




Sponsored Link
Ads by Google

Response Number 1
Name: Wolfbone
Date: September 21, 2006 at 23:02:56 Pacific
Reply:

It's because of the inexact representation of floating point numbers. For example, only positive integers < about 10^16 (I think) can be represented exactly as doubles so the error in larger numbers is bound to show up at some point:

printf("%f\n",1e23);
99999999999999991611392.000000

The way round the problem depends on exactly what you want to do.


0

Response Number 2
Name: Wolfbone
Date: September 22, 2006 at 02:04:37 Pacific
Reply:

s/can be represented/can all be represented/


0

Response Number 3
Name: wizard-fred
Date: September 22, 2006 at 22:24:52 Pacific
Reply:

There are high precision math packages that can handle n'th precision. They are slow because they work by using integer by parts, then combining. That will solve your rounding problem. It will be you problem to represent the math properly.


0

Response Number 4
Name: Guy
Date: September 25, 2006 at 17:03:33 Pacific
Reply:

Yes, a high precision math package using (I read between the lines) C/C++.

Maybe (?) another language that has built in support for this: Java

Maybe (?) another language that has seamless built in support for this: Ruby

Kinda depends ....... right tool for the right job.

Guy


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: computing large numbers. powers of

creating c++ class of a large number www.computing.net/answers/programming/creating-c-class-of-a-large-number/18883.html

can FORTRAN work with large numbers? www.computing.net/answers/programming/can-fortran-work-with-large-numbers/1140.html

Cmd - Large number work around www.computing.net/answers/programming/cmd-large-number-work-around/17533.html