- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
astep = 0.2
div = avmax/astep
n1 = int(avmax/astep)
n2 = int(div)
WRITE (*,*) 'int(avmax/astep)=', n1
WRITE (*,*) 'int(div), (where div=avmax/astep) =', n2
Link Copied
- 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
As you've found out, this is non-portable code. The results may change even with the same compiler, if you change the optimization switches. With default switches, I would expect CVF to be performing these evaluations in double precision, but 0.2 is a single precision constant, and you made sure of it by assigning the value to a single precision variable.
Your code says something like:
Take the binary single precision approximation to 0.2, invert it using the working precision (probably double), and give me thewhole part. Then do the same thing, but round off to single precision before taking the whole part. Evidently, the result depends on whether rounding 0.2 off to single precision rounds up or down. The compiler is not permitted to use decimal arithmetic to pre-calculate the results.
If you meant to use nint() rather than int(), that could be expected to give portable results on operations like these.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

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