- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a question concerning the following code:
real*8 :: floorval
real*8 :: max8int
max8int = 2**63-1
floorval = floor (max8int, 8)
The varibale "floorval" should have the value "2**63-1" but it has the value "-(2**63-1)". I am using compiler version 11.1.051. Am I missing something? Thank you very much in advance!
real*8 :: floorval
real*8 :: max8int
max8int = 2**63-1
floorval = floor (max8int, 8)
The varibale "floorval" should have the value "2**63-1" but it has the value "-(2**63-1)". I am using compiler version 11.1.051. Am I missing something? Thank you very much in advance!
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You want:
max8int - 2_8**63_8 - 1
The expression 2**63-1 is "default integer" and overflows. The 2**63 ends up as 0 (since all the 1 bits are shifted out) and thus max8int is -1.
I would suggest as an alternative:
max8int = HUGE(0_8)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - Steve Lionel (Intel)
You want:
max8int - 2_8**63_8 - 1
The expression 2**63-1 is "default integer" and overflows. The 2**63 ends up as 0 (since all the 1 bits are shifted out) and thus max8int is -1.
I would suggest as an alternative:
max8int = HUGE(0_8)
Thank you for clearing that up!
I have another question concerning the floor function. I have large real number (e.g. around 1.d+20) and would like to compute the floor-values of these numbers. For example:
real*8 :: val = 1.d+20
As far as I understand, the value "floor(val)" does not fit into an integer*8. Is there another way to compute the floor of such a large real number?
Thank you. Franz
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
FLOOR returns a REAL value with the same kind of its argument. However, do you understand that when you get to values as large as 1.0D20 that you've lost significance in the low "integer" bits? A REAL*8 can't represent integers larger than 2**52 or thereabouts. So larger than that, there's no point in doing FLOOR as you'll get the same value back.
What exactly are you trying to accomplish here? What is the algorithm?

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