File: class_82.f90

package info (click to toggle)
lfortran 0.59.0-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 56,736 kB
  • sloc: cpp: 168,052; f90: 74,272; python: 17,537; ansic: 7,705; yacc: 2,345; sh: 1,334; fortran: 895; makefile: 37; javascript: 15
file content (41 lines) | stat: -rw-r--r-- 1,146 bytes parent folder | download | duplicates (3)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
program class_82
    implicit none
    class(*), allocatable :: xi, xr, xl
    integer :: i
    real :: r
    logical :: l
    ! Test integer binary operations
    allocate(xi, source=5)
    select type (xi)
    type is (integer)
        i = xi * 2
        print *, i, xi
        if (i /= 10) error stop "Integer multiply failed"
        i = xi + 3
        print *, i, xi
        if (i /= 8) error stop "Integer add failed"
    end select
    ! Test real binary operations
    allocate(xr, source=3.0)
    select type (xr)
    type is (real)
        r = xr * 2.0
        print *, r, xr
        if (abs(r - 6.0) > 1e-5) error stop "Real multiply failed"
        r = xr + 1.5
        print *, r, xr
        if (abs(r - 4.5) > 1e-5) error stop "Real add failed"
    end select
    ! Test logical binary operations
    allocate(xl, source=.true.)
    select type (xl)
    type is (logical)
        l = xl .and. .false.
        print *, l, xl
        if (l) error stop "Logical AND failed"
        l = xl .or. .false.
        print *, l, xl
        if (.not. l) error stop "Logical OR failed"
    end select
    print *, "PASSED"
end program class_82