- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How does Compaq Fortran version 6.1 handle rounding (actually printing) of real numbers? Specifically, I have an expression which is evaluated to 0.65. When I print this number to a file using F3.1 formatting it prints as 0.6. It appears that the .05 is rounded down. Is there an easy way to ensure that in all such cases it is rounded to 0.7?
Thanks for any help.
Kevin
Thanks for any help.
Kevin
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
0.65 is not exactly representable - the actual internal value is approximately 0.649999976, which rounds down to 0.6. 0.7 would be incorrect.
I will note that if the value WERE exactly 0.65, then you'd still get 0.6 because IEEE rounding rules would be followed - a value exactly halfway between two representable values is rounded so that the low-order digit is even. (On VMS, VAX rounding rules would be followed if the VAX floating types were being used.) As another example, an IEEE 2.5 rounds to 2. in F6.0 format!
Note that the Fortran standard does not currently specify what "rounding" means, except in the particular case of the NINT intrinsic.
Our latest newsletter, sent to registered users, has an appropriate article on floating point that addresses some of these issues.
Steve
I will note that if the value WERE exactly 0.65, then you'd still get 0.6 because IEEE rounding rules would be followed - a value exactly halfway between two representable values is rounded so that the low-order digit is even. (On VMS, VAX rounding rules would be followed if the VAX floating types were being used.) As another example, an IEEE 2.5 rounds to 2. in F6.0 format!
Note that the Fortran standard does not currently specify what "rounding" means, except in the particular case of the NINT intrinsic.
Our latest newsletter, sent to registered users, has an appropriate article on floating point that addresses some of these issues.
Steve
![](/skins/images/8B5EA638CA3587CA763EE9EF53643DD4/responsive_peak/images/icon_anonymous_message.png)
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