- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi there,
We're using 64-bit ifort on linux and its version is 11.1 056.
I have to assign the value of a real*8 variable var_r8 to another real*4 variable var_r4.
If var_r8 is checked to be within upper/lower bounds of real*4, is it save to use
var_r4 = var_r8
In case var_r8 exceeds the smallest number which can be handled by real*4, var_r4 can be set as 0.0.
Your opinion is very much appreciated.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If your only criterion of safety is that the assignment doesn't overflow, you are OK under the condition abs(x) < huge(1_4)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tim,
Thanks a lot for the info. Function "huge" is the one to implement. Do you know the corresponding function to show the smallest real*4? I surfed the Internet but only found the compiler flags which handle floating point underflow. However, I need to assign real*8 to real*4 and those flags are not too useful.
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You implied you weren't concerned about underflow. Partial or full underflow will set in for abs(x) < tiny(x).
If you are talking about compile options for abrupt underflow (such as ifort default -ftz) those simply assure that there is no partial underflow, so that real(x, kind(1.) ) always gives 0. for abs(x) < tiny(x).
-ftz has an effect only when used to compile the main program. If you wish to switch underflow mode at run time, under
USE ieee_arithmetic
...
logical gradual_underflow
....
gradual_underflow= .....
call ieee_set_underflow_mode(gradual_underflow)
The only reason for introduction of these complications was that CPUs prior to Core I7-2 "Sandy Bridge" exhibited poor performance when encountering gradual underflow. It's not clear that these facilitate whatever reasons you may have for reducing double to single precision.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
HUGE and TINY are Fortran intrinsics; no need to implement them yourself, just look at ifort's excellent documentation. Also the masked assignment with the WHERE statement and construct may be consistent with your needs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tim and Repeat Offender,
Thanks a lot for the assistance. I've got all I need.
![](/skins/images/D3C0B914909A6564BBB97F4AD1ED1973/responsive_peak/images/icon_anonymous_message.png)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page