- #1
fluidistic
Gold Member
- 3,924
- 261
Hi,
I'm laughing, after having passed more than one hour on a very simple program I could finish it. It does the Euclidean division between 2 numbers that one type.
It is very inefficient I agree. I gave up doing it in a more efficient way in order to simplify it (for my brain at least). Nevertheless up till a billion it gives the answer almost instantly and take less than 5 seconds for a number like a billion, so it's fast after all.
So my guess is that the number is too big. (Strangely it says "runtime error" when in fact it didn't even tried to compute it and the message appears instantly). Has Fortran 90 a limit when computing numbers? If so, is the limit at 10 billions? It seems to me a very small limit for computer calculus.
Second question : How can programs like Mathematica, Maple, etc. give the number pi with say 1000000 digits if (my guess is that they are written in C) fortran and other programming languages cannot work with more than 8 digits or so?
Thanks in advance.
I'm laughing, after having passed more than one hour on a very simple program I could finish it. It does the Euclidean division between 2 numbers that one type.
It is very inefficient I agree. I gave up doing it in a more efficient way in order to simplify it (for my brain at least). Nevertheless up till a billion it gives the answer almost instantly and take less than 5 seconds for a number like a billion, so it's fast after all.
Ok here are my questions. I've tried a number greater than 10 billions and I got this message : "At line 9 of file mod2.f90 (unit = 5,file = 'stdin') Fortran runtime error: Integer overflow while reading item 1"program mod2
implicit none
Integer :: a,q,r,i,k
write(*,*)'Enter a number and its divisor'
read(*,*)a,k
q=k
i=1
do while (q<a)
q=k*i
i=i+1
end do
if (q>a) then
q=q-k
endif
i=i-2
r=a-i*k
if (r==k) then
write(*,*)a,'=',i+1,'*',k,'+0'
Else
write(*,*)a,'=',i,'*',k,'+',r
endif
end program mod2
So my guess is that the number is too big. (Strangely it says "runtime error" when in fact it didn't even tried to compute it and the message appears instantly). Has Fortran 90 a limit when computing numbers? If so, is the limit at 10 billions? It seems to me a very small limit for computer calculus.
Second question : How can programs like Mathematica, Maple, etc. give the number pi with say 1000000 digits if (my guess is that they are written in C) fortran and other programming languages cannot work with more than 8 digits or so?
Thanks in advance.