File: functions_30.f90

package info (click to toggle)
lfortran 0.45.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 46,332 kB
  • sloc: cpp: 137,068; f90: 51,260; python: 6,444; ansic: 4,277; yacc: 2,285; fortran: 806; sh: 524; makefile: 30; javascript: 15
file content (25 lines) | stat: -rw-r--r-- 806 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
program functions_30
    real :: x(4) = [1.0, 2.0, 3.0, 4.0]
    print *, maxval([1.0,x])
    if(maxval([1.0,x]) /= 4.0) error stop
    print *, max_func([1.0,x])
    if(max_func([1.0,x]) /= 4.0) error stop
    !! Assignment with function on rhs having lhs var in its arg
    x = x / norm(x)
    print *, x
    if(any(abs(x - [0.182574183, 0.365148365, 0.547722518, 0.730296731]) > 10e-12)) error stop
contains 
    real function max_func(x) result(y)
      real, intent(in) :: x(:)
      y = maxval(x)
    end function
    real function norm(vec) result(res)
      real, intent(in) :: vec(:)   
      integer :: i                 
      res = 0.0                    
      do i = 1, size(vec)
          res = res + vec(i)**2   
      end do
      res = sqrt(res)             
end function norm
end program