Operating System - HP-UX
1826737 Members
2525 Online
109702 Solutions
New Discussion

problem with lgamma function in f90

 
SOLVED
Go to solution
Krzysztof Kielak
Occasional Advisor

problem with lgamma function in f90

Hi,

I have problems calling lgamma function from fortran 90. In the following example the returned value should be 0 (because lgamma(1) = 0), but it's not:

rcc:fit# cat test.f
double precision x, r
x = 1.0
write (*,*) lgamma(x)
end
rcc:fit# f90 -lm test.f
test.f
main program

6 Lines Compiled
/usr/ccs/bin/ld: (Warning) At least one PA 2.0 object file (test.o) was detected. The linked output may not run on a PA 1.x system.
rcc3:fit# ./a.out
1082562470
rcc:fit#


Does anyone has any ideas why?
best regards
Chris
4 REPLIES 4
Nicolas Dumeige
Esteemed Contributor

Re: problem with lgamma function in f90

Hello,

My guess is that the linker is telling you that the builted binary is 64 bits and won't work on a 32 system.

Cheers,

Nicolas
All different, all Unix
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: problem with lgamma function in f90

No, that is a normal warning simply indicating that this code may not run on all HP boxes.

I just wrote a quickie C program and linked with -lm; the underlying lgamma function appears fine. It would be good to know if this is a problem with the write function (or perhaps the implicit format) or with the compiler itself. I would first assign the result of lgamma to your double precision variable, r. Write r using your existing format; if that fails use an explicit format and see if the results are any better. This will help separate out the "real" problem. You might want to stop the f90 compile at the assembly step and have a look at the .s source code.


It's always a good idea to look for cumulative compiler/linker/library patches but since you didn't bother to mention your version of compiler or HP-UX, I'm not going to bother looking.
If it ain't broke, I can fix that.
Nicolas Dumeige
Esteemed Contributor

Re: problem with lgamma function in f90

Mike Stroyan
Honored Contributor

Re: problem with lgamma function in f90

You need to specify the return type and the parameter passing convention before you call a function with a "C" language binding. The alias directive can be used to tell f90 that the parameter is passed by value instead of the fortran convention of pass by reference.

!$HP$ ALIAS lgamma(%VAL)
double precision lgamma
double precision x, r
x = 1.0
write (*,*) lgamma(x)
x = 3.0
write (*,*) lgamma(x)
x = 3.06
write (*,*) lgamma(x)
end