- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi!
I posted a question a few days ago concerning bit inquiry functions to replicate ones I found in an old Univac Fortran code I am trying to rewrite in FORTRAN90. I received a lot of great information from members here. Thank you very much.
Once again, in a nutshell, my goal is to load a floating point variable number (real) into a 32-bit word (that is the easy part!) and then I need to pull out various bits for some further calculations. Unlike the old UNIVAC code, FORTRAN90 bit inquiry instrinsics force me to use INTEGER variables, not REAL variable inputs. In order to work with INTEGER values, one of the responses suggested that I use an EQUIVALENCE statement and another responder suggested I use the TRANSFER statement. In looking at the documentation, both statements seem to do the same thing? Is one more preferable than the other, ie, faster?
Thank you again for all of your help.
Sincerely,
David
I posted a question a few days ago concerning bit inquiry functions to replicate ones I found in an old Univac Fortran code I am trying to rewrite in FORTRAN90. I received a lot of great information from members here. Thank you very much.
Once again, in a nutshell, my goal is to load a floating point variable number (real) into a 32-bit word (that is the easy part!) and then I need to pull out various bits for some further calculations. Unlike the old UNIVAC code, FORTRAN90 bit inquiry instrinsics force me to use INTEGER variables, not REAL variable inputs. In order to work with INTEGER values, one of the responses suggested that I use an EQUIVALENCE statement and another responder suggested I use the TRANSFER statement. In looking at the documentation, both statements seem to do the same thing? Is one more preferable than the other, ie, faster?
Thank you again for all of your help.
Sincerely,
David
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It's certainly likely that equivalence and transfer may work alike in your usage:
integer i
real r,x
equivalence(r,i)
Then
r = x
and
i = transfer(x,i)
accomplish the same thing. Even though I'm not accustomed to transfer(), I think transfer() is much clearer to humans, as it keeps the functionality in one place, and avoids introduction of an otherwise meaningless new variable name.
integer i
real r,x
equivalence(r,i)
Then
r = x
and
i = transfer(x,i)
accomplish the same thing. Even though I'm not accustomed to transfer(), I think transfer() is much clearer to humans, as it keeps the functionality in one place, and avoids introduction of an otherwise meaningless new variable name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The difference is that the result of TRANSFER is an expression which needs to be used or assigned. EQUIVALENCE sets up "storage association" between two variables and this has wide effects on the generated code (in preventing optimizations.)
As Tim suggests, use of TRANSFER makes it much more obvious what is going on. Code that assigns to r and then reads from i doesn't suggest that they are the same storage - you'd have to go back and look for an EQUIVALENCE to see if they might be.
Another advantage of TRANSFER is that you can assign a run-time shape to the result which you can't with EQUIVALENCE.
As Tim suggests, use of TRANSFER makes it much more obvious what is going on. Code that assigns to r and then reads from i doesn't suggest that they are the same storage - you'd have to go back and look for an EQUIVALENCE to see if they might be.
Another advantage of TRANSFER is that you can assign a run-time shape to the result which you can't with EQUIVALENCE.

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