Skip to content
Snippets Groups Projects
Commit 4057eb6c authored by Vogt, Georg's avatar Vogt, Georg
Browse files

operation_priority.f95 added and clean up

operation_priority.f95 shows the difference between user defined
operations and default operations

.gitignore to ignore binary files -> mv txt files to *.txt
parent 081afad3
No related branches found
No related tags found
No related merge requests found
# ignore all
*
# Unignore all with extensions
!*.*
# Unignore Makefiles
!Makefile
!makefile
### Above combination will ignore all files without extension ###
# Ignore files with extension `.o` & `.mod` & `.out`
*.o
*.mod
*.out
File moved
File moved
module int_type
implicit none
type inte
integer :: i
end type inte
interface operator(**)
module procedure exp2
end interface
interface operator(+)
module procedure plus
end interface
interface operator(-)
module procedure neg
end interface
interface operator(.e.)
module procedure exp2
end interface
interface operator(.p.)
module procedure plus
end interface
interface operator(.n.)
module procedure neg
end interface
contains
function exp2(e,x)
type(inte), intent(in) :: e,x
type(inte) :: exp2
exp2%i=e%i**x%i
end function exp2
function plus(e,x)
type(inte), intent(in) :: e,x
type(inte) :: plus
plus%i=e%i+x%i
end function plus
function neg(x)
type(inte) :: neg
type(inte), intent(in) :: x
neg%i = -x%i
end function neg
end module int_type
program operation_priority
use int_type
implicit none
type(inte) :: a, b
a%i = 2; b%i=0
write(*,*) "a**a**b ", a**a**b ! rechts nach links wie nächste Zeile
write(*,*) "a**(a**b) ", a**(a**b) ! 2**2**0 = 2**1 = 2
write(*,*) "(a**a)**b ", (a**a)**b ! (2**2)**0 = 4**0 = 1
write(*,*) "a.e.a.e.b ", a.e.a.e.b ! eigener Operator: links nach rechts: = 1
write(*,*) "a+a**a ", a+a**a ! exp vor +
write(*,*) "a**a+a ", a**a+a ! exp vor + : 2**2+2=4+2=6
write(*,*) "a.p.a.e.a ", a.p.a.e.a ! eigener Operator: links nach rechts (2+2)**2=16
write(*,*) "a.e.a.p.a ", a.e.a.p.a ! eigener Operator: links nach rechts 2**2+2=6
write(*,*) "a+a.e.a ", a+a.e.a ! + vor eigener Operator (binär) (2+2)**2=16
write(*,*) "-a**a ", -a**a ! exp vor -: -2**2=-4
write(*,*) ".n.a**a ", .n.a**a ! eigener Operator (unär) vor exp: (-2)**2=4
end program operation_priority
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment