- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Hi. Since I am doing some fundamental calculation, this problem came up, as:

! This is good. integer(8), parameter :: max_int64 = int(16#8000000000000000, kind = 8) write(*,*) max_int64 ! This is bad. write(*,*) int(16#8000000000000000, kind = 8)

The upper case gives an correct output of 9151314442816847872 but the lower one prints only 0. why is that? Thanks for any help.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

I would expect these to be the same, but I can imagine why the compiler has a problem with it. Nevertheless, you are on extremely thin ice with your use of this non-standard syntax from a time when 64-bit didn't exist on the platform. If I interpret the documentation correctly, the expected value is zero because the # syntax for "integer constants" has a kind of "default integer". I won't even start to ask why you are calling this hex value MAX_INT64 since it is not at all the maximum 64-bit integer value - indeed, it is the minimum integer value. If you truly want the largest integer value for kind 8, use HUGE(0_8).

Link Copied

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

I would expect these to be the same, but I can imagine why the compiler has a problem with it. Nevertheless, you are on extremely thin ice with your use of this non-standard syntax from a time when 64-bit didn't exist on the platform. If I interpret the documentation correctly, the expected value is zero because the # syntax for "integer constants" has a kind of "default integer". I won't even start to ask why you are calling this hex value MAX_INT64 since it is not at all the maximum 64-bit integer value - indeed, it is the minimum integer value. If you truly want the largest integer value for kind 8, use HUGE(0_8).

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

I see, and I have found the page about "Determining the Data Type of Nondecimal Constants" in the manual. Thanks Steve and BTW, max is a mistake.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

The section you want is "Integer Constants" - the # syntax is treated differently from the BOZ syntax.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

! This is good. integer(8), parameter :: max_int64=int(Z'8000000000000000', kind = 8 ) write(*,*) max_int64 ! This is good write(*,*) int(Z'8000000000000000', kind = 8 )

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

FWIW

Z'8000000000000000'

Has sign bit set and remainder bits are 0 thus representing min_int64.

(Z'8000000000000000' - 1_8) would result in sign bit 0 and remainder bits set to 1's would represent max_int64

And , -HUGE(0_8) would produce a number 1 greater than the smallest negative number.

It is disputable as to if Z'8000000000000000' represents -0, or potentially arguable as an integer NaN, though the hardware will treat this as .lt. 0.

Jim Dempsey

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

So for safely use, maybe I should turn to the boz form all the time for constants based other than 2,8,16 are not frequently used anyway. Thanks for all.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Blane J. wrote:

So for safely use, maybe I should turn to the boz form all the time for constants based other than 2,8,16 are not frequently used anyway. Thanks for all.

The BOZ form is standards compliant so is the best way even though it seems a little clumsy at times. I aim to be able to compile any code I work on with standards checking on, it is a good thing to aim for.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

There is at least one other non-standard convention for specifying byte values for CHARACTER*1 variables:

C CHARACTER*1 CCR, CLF DATA CCR/'0D'X/, CLF/'0A'X/

Until I saw this in some old F77 code a few months ago (taken from an OS-2 code repository), I had never seen it.

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