Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Floor Function

franzw82
Beginner
913 Views
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!
0 Kudos
3 Replies
Steven_L_Intel1
Employee
913 Views

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)

0 Kudos
franzw82
Beginner
913 Views

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


0 Kudos
Steven_L_Intel1
Employee
913 Views

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?
0 Kudos
Reply