@seasoned geek said you cannot have ==
. But if you really want it for type logical you can always overload it, as in this little program based on one testing a different aspect of .eqv.
by @kargl.
program foo
implicit none
interface operator(==)
procedure eq12, eq21
end interface operator(==)
character(*), parameter :: fmt = '(A,2L2,3I2)'
logical(1) a1 ! nonportable gfortran kind=1 value
logical(2) a2 ! nonportable gfortran kind=2 value
a1 = .true._1
a2 = .true._2
if (a1.eqv.a2) print fmt,'a1.eqv.a2',a1,a2,kind(a1),kind(a2),kind(a1.eqv.a2)
if (a2.eqv.a1) print fmt,'a2.eqv.a1',a2,a1,kind(a2),kind(a1),kind(a2.eqv.a1)
if (a1 == a2) print fmt, 'a1 == a2', a1,a2,kind(a1), kind(a2),kind(a1==a2)
if (a2 == a1) print fmt, 'a2 == a1', a2,a1,kind(a2), kind(a1),kind(a2==a1)
contains
logical(2) function eq12(p,q)
logical(1),intent(in)::p
logical(2),intent(in):: q
eq12 = p.EQV.q
end function eq12
logical(2) function eq21(p,q) !
logical(2),intent(in)::p
logical(1),intent(in):: q
eq21 = p.EQV.q
end function eq21
end program foo
That compiled and ran in my x86_64 Ubuntu system with both gfortran and ifort, giving the same output What surprised me was that the kind type parameter value of the result of a logical intrinsic binary operation is processor dependent (see f2023 A.2), so I had to guess whether to declare the functions eq12
and eq21
as logical(1)
or logical(2)
.
If you want to do such things yourself, you should check how the precedence rules work for.eqv.
and ==