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

Ceiling Function

Michael8
Beginner
896 Views
Hello:

I feel like I'm missing something very basic. I have created the following test program that is the following 4 lines:

program Test

integer :: i = ceiling(2.0d0)

write(6, '(2I)') ceiling(2.0d0), i

end program Test



Why does it give me a result of 2 and 3? Shouldn't it be 2 for both parts of the write statement?

Thanks.
Michael
0 Kudos
7 Replies
Steven_L_Intel1
Employee
896 Views
Yes, it should. This looks like a bug. Thanks. I'll report it. Issue ID is DPD200157393.
0 Kudos
Michael8
Beginner
896 Views

OK, thanks. For a while there, I thought I was going insane.

Michael

0 Kudos
Steven_L_Intel1
Employee
896 Views
The issue seems to be the use in an "initialization expression". This is evaluated at compile-time and it seems, in this case, incorrectly. This bug has been there a long time, it would seem...
0 Kudos
Michael8
Beginner
896 Views
Yes, I noticed it was just a problem during initialization. The easy workaround would be to just have the declaration and the initialization as 2 separate steps. The problem we're having with that is that we're trying to use it to initialize a parameter, so we can't break it up.

Thanks.
Michael
0 Kudos
Steven_L_Intel1
Employee
896 Views
If you know that the value is positive, you can substitute this:

int(X - spacing(X)) + 1

It's a bit of a hack but I think it gives the same result. If the value can be negative, then one can be creative like this:

sign(int(abs(X) - spacing(X)) + 1,int(x))
0 Kudos
Steven_L_Intel1
Employee
896 Views
This was fixed in version 12.
0 Kudos
Michael8
Beginner
896 Views
Thanks, Steve!

Michael
0 Kudos
Reply