- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Will someone confirm below is a problem with CVF6.6B ?
program cvf_rounding_inconsistency
implicit none
real,parameter :: b = 0.002
integer :: a, n
do a = 15320499,15320499
n = a * b
write (*,*) n ! = 30640 truncates
end do
a = 15320499
n = a * b
write (*,*) n ! = 30641 rounds
end program
This problem surfaced when testing a CLF poster's
rounding case complaint for his unnamed compiler.
If I compile with /nooptimize the output truncates
BOTH outputs above to 30640 ??
program cvf_rounding_inconsistency
implicit none
real,parameter :: b = 0.002
integer :: a, n
do a = 15320499,15320499
n = a * b
write (*,*) n ! = 30640 truncates
end do
a = 15320499
n = a * b
write (*,*) n ! = 30641 rounds
end program
This problem surfaced when testing a CLF poster's
rounding case complaint for his unnamed compiler.
If I compile with /nooptimize the output truncates
BOTH outputs above to 30640 ??
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There's no inconsistency in how CVF rounds, irrespective of optimization.
For floats, the default rounding mode is round to nearest. Rounding mode doesn't apply to integers. Use NINT. NINT(a*b) will give 30641 all the time.
Ciao,
Gerry T.
For floats, the default rounding mode is round to nearest. Rounding mode doesn't apply to integers. Use NINT. NINT(a*b) will give 30641 all the time.
Ciao,
Gerry T.
- 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
Yes, I meant to say that my default is to round to nearest so YMMV.
Ciao,
Gerry T.
Ciao,
Gerry T.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Actually, 'round to even' is a loose way of saying take the result whose LSB is 'off' in the event of a tie in 'round to nearest'. From the Feb/2003 IEEE 754 standard:
4.1. Round to Nearest
An implementation of this standard shall provide round to nearest as the default rounding mode. In this mode the representable value nearest to the infinitely precise result shall be delivered; if the two nearest representable values are equally near, the one with its least significant bit zero shall be
delivered....
The CVF docs correctly use the term 'round to nearest' as does F2K.
Ciao,
Gerry T.
4.1. Round to Nearest
An implementation of this standard shall provide round to nearest as the default rounding mode. In this mode the representable value nearest to the infinitely precise result shall be delivered; if the two nearest representable values are equally near, the one with its least significant bit zero shall be
delivered....
The CVF docs correctly use the term 'round to nearest' as does F2K.
Ciao,
Gerry T.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
n = a * b ! = 36040
n = a * b ! = 36041
obviously in the 2nd evaluation above
CVF didnt follow the same rule it followed in the 1st
evaluation..
Hence my subject line: rounding inconsistency
n = a * b ! = 36041
obviously in the 2nd evaluation above
CVF didnt follow the same rule it followed in the 1st
evaluation..
Hence my subject line: rounding inconsistency

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