- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
Hello!
I've gottwo real(8) type variables X and Y. When I calculate Y=sqrt(X), thereappears noproblem with the value of Y. But when I multiply Y with another real(8) number, I cannot get the true result.
What do I need to do to obtain true result of this multiplication.
- Balises:
- Intel® Fortran Compiler
Lien copié
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
As with your previous question about using the LOG function, a smallexample program or some sample code which shows the problem is necessary before anyone can giverelevant advice.
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
program
questionimplicit none
parameter
wp = KIND( 1.0D0 )real (8) n,a,y,g,q0,q17,q19,q12,q13,q1
real (wp) T1,T2,q18
n=10e21_8
a=2.5_8
y=0.01_8
g=0.129_8
T1=0.096_wp
T2=209000_wp
q0=((a**2)+(b**2)+(c**2))/8
q17=(n*(a**2))/(8*q0)
q18=y/(1+(g*
log(T2/T1)))q19=4*
sqrt(2*q0)q12=q17*q18*q19
q13=g*(T2-T1)
q1=q12*q13
end program question
Everything isOK until q1. But q1 is not calculatedcorrectly. What is the reason?
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
fortcom: Error: sqrtbug.f90, line 23: This name does not have a type, and must have an explicit type.
q0=((a**2)+(b**2)+(c**2))/8
------------^
fortcom: Error: sqrtbug.f90, line 23: This name does not have a type, and must have an explicit type.
q0=((a**2)+(b**2)+(c**2))/8
-------------------^
compilation aborted for sqrtbug.f90 (code 1)
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
The variables b and c have not only not been declared butthey have not been givenvalues before they are used in the computation ofq0. Thus, any result calculated for q1 is meaningless.
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
Sorry for the missing part. Here it is again:
program
questionimplicit none
parameter
wp = KIND( 1.0D0 )real (8) n,a,b,c,y,g,q0,q17,q19,q12,q13,q1
real (wp) T1,T2,q18
n=10e21_8
a=2.5_8
b=2.4_8
c=2.3_8
y=0.01_8
g=0.129_8
T1=0.096_wp
T2=209000_wp
q0=((a**2)+(b**2)+(c**2))/8
q17=(n*(a**2))/(8*q0)
q18=y/(1+(g*
log(T2/T1)))q19=4*
sqrt(2*q0)q12=q17*q18*q19
q13=g*(T2-T1)
q1=q12*q13
end program question
Everything isOK until q1. But q1 is not calculatedcorrectly. What is the reason?
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
sqrtbug.f90:5:
parameter wp = KIND( 1.0D0 )
1
Error: Unclassifiable statement at (1)
sqrtbug.f90:9.8:
real (wp) T1,T2,q18
1
Error: Symbol 'wp' at (1) has no IMPLICIT type
sqrtbug.f90:23.11:
T1=0.096_wp
1
Error: Missing kind-parameter at (1)
sqrtbug.f90:25.12:
T2=209000_wp
1
Error: Missing kind-parameter at (1)
sqrtbug.f90:31.3:
q18=y/(1+(g*log(T2/T1)))
1
Error: Symbol 'q18' at (1) has no IMPLICIT type
sqrtbug.f90:31.21:
q18=y/(1+(g*log(T2/T1)))
1
Error: Symbol 't1' at (1) has no IMPLICIT type
sqrtbug.f90:31.18:
q18=y/(1+(g*log(T2/T1)))
1
Error: Symbol 't2' at (1) has no IMPLICIT type
i.e. it looks like ifort failed to diagnose the failure to declare wp, so the program indeed is still non-compliant.
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
I hadn't written the "write" part of the code not to preoccupy more space. The full version of the code is:
program question
implicit none
parameter
wp = KIND( 1.0D0 )real (8) n,a,b,c,y,g,q0,q17,q19,q12,q13,q1
real (wp) T1,T2,q18
n=10e21_8
a=2.5_8
b=2.4_8
c=2.3_8
y=0.01_8
g=0.129_8
T1=0.096_wp
T2=209000_wp
q0=((a**2)+(b**2)+(c**2))/8
q17=(n*(a**2))/(8*q0)
q18=y/(1+(g*
log(T2/T1)))q19=4*
sqrt(2*q0)q12=q17*q18*q19
q13=g*(T2-T1)
q1=q12*q13
write (*,*) q1
end program question
There is no error about the "parameter" statement. The code runs well. But there is something wrong about the calculation of q1. The real value of it must be 2.810892534E24, but the calculated value is2.810892535844940E24.
What is the reason?
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
integer, parameter :: wp = kind(1.0D0)
or
integer wp
parameter (wp = kind(1.0D0))
The version you have is an extension.
That said, I don't know why you expect a different answer. As best as I can tell, you are getting a correct result. I reran the program in quad precision and it agreed with the double value to all the digits.
On what combination of computer, OS and compiler did you see the other answer?
You do have one interesting bug in your code, though it is harmless. You write:
T2=209000_wp
Since 209000 is an integer constant, you are getting 209000_8 (INTEGER(8)) which is then converted to REAL(8). This should really be:
T2 = 209000._wp
I can't see how this would change the result unless the other compiler you ran this on did not support INTEGER(8).
It would be useful for you to print all the variables and run it on both systems to see where the difference comes in.
- S'abonner au fil RSS
- Marquer le sujet comme nouveau
- Marquer le sujet comme lu
- Placer ce Sujet en tête de liste pour l'utilisateur actuel
- Marquer
- S'abonner
- Page imprimable