MODULE Integer_Complex_Arithmetic IMPLICIT NONE CONTAINS FUNCTION Addition(ic1,ic2) INTEGER, INTENT(IN), DIMENSION(2) :: ic1, ic2 INTEGER, DIMENSION(2) :: Addition Addition = ic1 + ic2 END FUNCTION Addition FUNCTION Subtraction(ic1,ic2) INTEGER, INTENT(IN), DIMENSION(2) :: ic1, ic2 INTEGER, DIMENSION(2) :: Subtraction Subtraction = ic1 - ic2 END FUNCTION Subtraction FUNCTION Multiplication(ic1,ic2) INTEGER, INTENT(IN), DIMENSION(2) :: ic1, ic2 INTEGER, DIMENSION(2) :: Multiplication Multiplication(1) = ic1(1)*ic2(1) - ic1(2)*ic2(2) Multiplication(2) = ic1(1)*ic2(2) + ic1(2)*ic2(1) END FUNCTION Multiplication FUNCTION Division(ic1,ic2) INTEGER, INTENT(IN), DIMENSION(2) :: ic1, ic2 INTEGER, DIMENSION(2) :: Division Division = Multiplication(ic1,(/ic2(1),-ic2(2)/))/& (ic2(1)*ic2(1)+ic2(2)*ic2(2)) END FUNCTION Division FUNCTION Exponentiation(ic1,exp) INTEGER, INTENT(IN), DIMENSION(2) :: ic1 INTEGER, INTENT(IN) :: exp INTEGER, DIMENSION(2) :: Exponentiation INTEGER i Exponentiation = (/1,0/) ! for exp = 0 DO i = 1, exp Exponentiation = Multiplication(Exponentiation,ic1) END DO END FUNCTION Exponentiation END MODULE Integer_Complex_Arithmetic PROGRAM Testo USE Integer_Complex_Arithmetic IMPLICIT NONE PRINT*, "Addition((/1,2/),(/3,4/))", & Addition((/1,2/),(/3,4/)) PRINT*, "Subtraction((/1,2/),(/3,4/))",& Subtraction((/1,2/),(/3,4/)) PRINT*, "Division((/1,2/),(/3,4/))", & Division((/1,2/),(/3,4/)) PRINT*, "Division((/3,4/),(/3,4/))", & Division((/3,4/),(/3,4/)) PRINT*, "Division((/3,4/),(/1,2/))", & Division((/3,4/),(/1,2/)) PRINT*, "Multiplication((/1,2/),(/3,4/))",& Multiplication((/1,2/),(/3,4/)) PRINT*, "Exponentiation((/1,2/),3)", & Exponentiation((/1,2/),3) END PROGRAM Testo
This produces,
Addition((/1,2/),(/3,4/)) 4 6 Subtraction((/1,2/),(/3,4/)) -2 -2 Division((/1,2/),(/3,4/)) 0 0 Division((/3,4/),(/3,4/)) 1 0 Division((/3,4/),(/1,2/)) 2 0 Multiplication((/1,2/),(/3,4/)) -5 10 Exponentiation((/1,2/),3) -11 -2