The program below gives this error message:
$ gfortran Ambiguous.f95 -o Ambiguous
Ambiguous.f95:46.14:
y = sqrt(x)
1
Error: Name 'sqrt' at (1) is an ambiguous reference to 'sqrt' from module '(intrinsic)'
Enabling the d+75 definition of max_allowed gives no error and produces the expected
result when the program runs.
Why is there ambiguity in the sqrt usage when the sqrt in mod1 has a double precision
argument and sqrt(x) has a type (pair) argument?
Thanks,
Dave Smith
module mod1
! double precision :: max_allowed = 1.0d+75
double precision :: max_allowed = sqrt(sqrt(huge(max_allowed)))
integer :: kw = 6
end module mod1
module mod2
type pair
double precision :: a_pair(2) = (/ 0, 0 /)
end type
interface sqrt
module procedure sqrt_pair
end interface
contains
function sqrt_pair(a)
use mod1
implicit none
type (pair) :: a, sqrt_pair
intent (in) :: a
sqrt_pair%a_pair(1) = min( sqrt(a%a_pair(1)), max_allowed )
sqrt_pair%a_pair(2) = min( sqrt(a%a_pair(2)), max_allowed )
end function sqrt_pair
end module mod2
program test
use mod1
use mod2
type (pair) x, y
x%a_pair(1) = 1.23d+100
x%a_pair(2) = 1.23d+200
y = sqrt(x)
write (kw,*) ' y = ', y%a_pair(1), y%a_pair(2)
end program test
|