Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem handling big real numbers

Status
Not open for further replies.

vibhava

Programmer
Apr 20, 2008
19
US
hi,
yesterday i got the answer for how to handle a big integer. today i am having problem with real number. i have written a code which in the end gives me two big integers for example:

1329527587452 and
789000066068
i need to get the ratio of these 2 number (number 2 divided by number 1). the problem is that the ratio will be a real number and i don't know how to treat or define large real number. i tried using:
real (kind=i8),dimension(2000)::ratio
but i guess it can be used with integers only.

i am at the very end of my program. i would really appreciate if someone can help me with this problem.

Regards,

Vibhava

 
Real numbers go up to 10**308. Do your numbers get that big or do you want stuff to something like 30 digits precision?
 
no my final answer will be 0.593443922 (using a calculator for the above given two values). my prblem is that i have defined above two numbers as Integer (kind = i8) where i8=8 to handle such a big value. however when i am dividing them and storing the result into a real variable i am getting an answer=1 always.

integer(kind=i8)::x,y
real (kind=i8),dimension(2000)::ratio
.
.
.
ratio=y/x

where x,y are above mentioned number but my answer is coming = 1 instead of 0.593443922.

vibhava
 
That is because it is integer division. Not sure why you're getting 1. You should be getting 0. Anyway, if you wish to divide integers as reals, use the dble function.
Code:
ratio = dble(y) / dble(x)
 
The problem is that the integers that you have in your
code have too many digits for most systems.
The largest integers are typically 2147483647.

To enter your number in the program, you need
to write:
1329527587452d0 and
789000066068d0

and they then become double precision.
The division can proceed, and you assign the result to a
double-precision variable.

dble(k) etc will experience the same
problem because the assignment to k
will have already lost digits for the same reason.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top