abs(3f) - [FORTRAN:INTRINSIC:NUMERIC] Absolute value
result = ABS(A)
abs(A) computes the absolute value of numeric argument A.
A the type of the argument shall be an INTEGER, REAL, or COMPLEX scalar or array with INTENT(IN).
If A is of type INTEGER or REAL, the value of the result is |A| and of the same type and kind as the input argument.if A is COMPLEX with value (X, Y), the result is a REAL equal to a processor-dependent approximation to SQRT(X**2 + Y**2) computed without undue overflow or underflow.
Sample program:
program demo_abs integer :: i = -1, iout real :: x = -1.e0, xout, zout complex :: z = (-3.e0,4.e0) doubleprecision :: r8 = 45.78D+00, dout write(*,*)INPUTS:,i,x,z,r8 iout = abs(i) xout = abs(x) zout = abs(z) dout = abs(r8) write(*,*)OUTPUTS:,iout,xout,zout,dout write ( *, (a,f12.4,12x,f12.4) ) Double precision , -r8, abs(r8) ! COMPLEX ! 3 - 4 -5 right triangle test : write(*,*)The abs() of (3.0,4.0) should be 5.0,abs((3.0,4.0)) ! ELEMENTAL write(*,*)abs is ELEMENTAL: ,abs([-10, 20, 0, -1, -3, 100]) end program demo_absResults:
INPUTS: -1 -1.00000000 (-3.00000000,4.00000000) 45.780000000000001 OUTPUTS: 1 1.00000000 5.00000000 45.780000000000001 Double precision -45.7800 45.7800 The abs() of (3.0,4.0) should be 5.0 5.00000000 abs is ELEMENTAL: 10 20 0 1 3 100
[[FORTRAN 77]] and later
Elemental function
abs (3) | March 11, 2021 |