Silverfrost Forums

Welcome to our forums

Compiler bug, caused by use of log_gamma (?)

11 Oct 2016 12:36 #18098

FTN95 8.05 outputs an erroneous result for the first run of the DO loop and then aborts with an X87 stack fault when the following program is compiled and run in 32-bit mode. There is no error with /64. I am not sure whether the bug is directly related to the use of the F2008 function log_gamma. The bug goes away if log_gamma is replaced by log.

program xloggam
implicit none
real :: p,q(2),x
integer :: ifault,i
data p/2.0/, q /10.0,20.0/

do i=1,2
   x = log_gamma(p)+log_gamma(q(i))-log_gamma(p+q(i))
   write(*,10)q(i),x
end do

10 format(F8.0,ES16.8)
end program

If the unused variable ifault is removed, the output for i = 1 is changed, although still incorrect.

12 Oct 2016 6:03 #18101

Thank you for the feedback. I have logged this as a bug that needs fixing.

I can get it to work if the 3 log_gamma results are stored separately and then combined.

12 Oct 2016 12:58 #18103

Quoted from PaulLaidler I can get it to work if the 3 log_gamma results are stored separately and then combined.

Thanks Paul. Yes, storing the result of each term in memory would reduce the chance of X87 stack overflow, but if the CDECL calling convention applies, ' registers ST0 to ST7 must be empty (popped or freed) when calling a new function, and ST1 to ST7 must be empty on exiting a function' (quoting from Wikipedia). Therefore, two or three registers should suffice to evaluate the expression, unless log_gamma is inlined.

12 Oct 2016 1:48 #18104

Thank you. I think that you are correct so I should not be too difficult to fix.

20 Jan 2017 10:17 #18727

This bug has been fixed for the next release.

20 Jan 2017 12:03 #18728

I look forward to that release, thanks.

Please login to reply.