- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I notice that when I assign a value to a variable and it is passed into the subroutine. I found that the value changed. How can I maintain the precision. all the variables I have declared them as double precision. Some values they changed but some does not.
Do you have any ideas on this issue.
Thank you so much for your help.
Best Regards,
Jingfen
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can you please give some example code? it is difficult to understand what is happening without examples.
Using the compiler option /fp:precise may be useful to look at.
David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You saidwhen "it is passed into the subroutine I found that the value changed"
You asked "How can I maintain the precision?"
Do you really mean "precision" ?
As David says, it is difficult to give you a definitive answer without us seeing at least a relevant portion of code.
But ...
Could it be that you have an argument mismatch ?
example :
double precision x
x = 3.14159265358979d0
call asub(x) ! there is a mismatch here
The actual argument X needs to match the "dummy" argument W in asub
subroutine asub(w)
realw ! Herew is SINGLE precision
! any value assigned toit will be single precision
w= 3.14159
...
If you suspect this may beyour problem you should turn on the diagnostics to check routine interfaces when you build your exe
Les
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[fortran]program tstwill print bogus output such as
double precision :: x
x=4*atan(1d0)
call asub(x)
end program tst
subroutine asub(x)
real :: x
write(*,10)x
10 format(G18.10)
return
end subroutine asub
[/fortran]
[bash] 0.3370280550E+13instead of the value of \pi.
[/bash]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Mismatches of this type (REAL and DOUBLE) can cause more catastrophic errors than mere loss of precision. If the MMX/XMM registers are used to pass real arguments rather than the x87 stack
Yes I thought about the problem ofstack corruption (due to argument mismatch)after I posted, andlater thought the original problem might beaboutsimple assignmentwhere if one has
X = 3.1415926535897932384626433832795
the numeric literal is single precision no matter how many digits are specified. The rhs is evaluated first and then the SINGLE precision result is assigned to the lhs.If X is double precision then the trailing bits are set to zero.
Les
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dearfriends,
Thank you so much for yourkind help.I am moreclear aboutwhat might cause the loss of precision.
But, Sorry,because I was working witha user subroutine to be called by another software called ABAQUS.And Causethe data Icompared belong to two different integration point. In the two sets of data, some values arethe same and othersarenot. Soat the first thought, I thought it was the problem of the loss of precision between subroutines.
But, I also output the value of one variable in the subroutine. it is as below.
-------------------------------------------------------------------------
DOUBLE PRECISION TOL,
TOL=1.0E-6
WRITE(7,*) "TOL=",TOL
--------------------------------------------------------------------------
but the results gives as : TOL= 9.999999974752427E-007
It's not called by other subroutines. so it is also a kind of loss of precision? did I get it wrong?
Thank you so much.
Jingfen Chen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
TOL=1.0D-6 ! see D instead E
Jakub
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
doubleVariable = 3742.37D0
in order to maintain the precision. With 3742.37 you set only the first 4 Bytes and the other 4 are random. Thats a common issue with IVF, so just add a D0 (zero, not the letter o) after your number.
Markus
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That's what every compiler is supposed to do, and the topic of mixed precision and the related topic of mixed types are both covered well in the compiler documentation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hi, all,
thank you so much for your help. I change the "E" into "D" and it works. And i am also more clear about this problem.assign a value of the singl precision will also change the type of the variable even though i have already declare it as double precision. I got it.
Best Regards,
Jingfen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
tol=1.0e-6
means
1. load to the mathematic coprocessor single precision value 1.0E-6
2. so on the coprocesssor appears something like 1.000000956446544 because single precision have only 6 decimal places and other digits are garbage
3. then put value on the coprocessor to the double precision variable tol
4. in the tol variable is 1.000000956446544
you can use also
tol=DBLE(1.0E-6)
first is single precision value converted to double and then assigned.
Jakub

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page