Showing results for 
Search instead for 
Did you mean: 
New Contributor I

Taking the absolute value of a logical argument: no compilation error

I had accidently taken the absolute value of a logical argument and Intel Fortran did not flag it as a compiler error. In fact, the code ran fine until I happened to detect the error indirectly through an erroneous output in another variable. Is this consistent with the Fortran standard? (On a different note, do not see option in new forum to format the code below as a F90 source).

program main
implicit none
real(kind = :: x
x = 1.0d-7
if (abs(abs(x) <= 1.0d-6)) then
print *, 'error: absolute value of a logical argument is not allowed'
read *
end if
end program main

0 Kudos
2 Replies
New Contributor I

I noticed that the code I pasted above left out portions of the original file ex. real(kind = :: x. So attaching the source file of the test example.

Black Belt Retired Employee

Any time you want to ask whether something is standard, the first thing you should do is invoke the compiler with standards warnings enabled:

D:\Projects>ifort /stand test_abslgt.f90
Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel(R) 64, Version 2021.1.2 Build 20201208_000000
Copyright (C) 1985-2020 Intel Corporation.  All rights reserved.

test_abslgt.f90(6): warning #7056: Allowing integer arguments to be logical for this intrinsic function is not standard Fortran 2018
  if (abs(abs(x) <= 1.0d-6)) then
test_abslgt.f90(6): warning #6188: Fortran 2018 requires a LOGICAL data type in this context.   [ABS]
  if (abs(abs(x) <= 1.0d-6)) then


Intel Fortran, like DEC Fortran before it for decades, has an extension that allows free conversion between numeric and logical types. This was handy in the VMS days, though ill-considered in hindsight. I did manage to get this removed from list-directed input (by default, you can still re-enable it).