File: bindc_11.f90

package info (click to toggle)
lfortran 0.60.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 58,412 kB
  • sloc: cpp: 173,406; f90: 80,491; python: 17,586; ansic: 9,610; yacc: 2,356; sh: 1,401; fortran: 895; makefile: 37; javascript: 15
file content (41 lines) | stat: -rw-r--r-- 1,019 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
module bindc_11_mod
use, intrinsic :: iso_c_binding, only: c_float
implicit none
contains

    complex(c_float) function twice(z) result(r) bind(c)
        complex(c_float), value, intent(in) :: z
        r = z + z
    end function twice

end module bindc_11_mod

program bindc_11
use, intrinsic :: iso_c_binding, only: c_float
use bindc_11_mod, only: twice
implicit none

    complex(c_float) :: z, r
    real(c_float) :: re, im
    integer :: i

    z = cmplx(5.0_c_float, 7.0_c_float, kind=c_float)

    r = twice(z)
    re = real(r, kind=c_float)
    im = aimag(r)
    if (abs(re - 10.0_c_float) > 1.0e-6_c_float) error stop
    if (abs(im - 14.0_c_float) > 1.0e-6_c_float) error stop

    r = cmplx(0.0_c_float, 0.0_c_float, kind=c_float)
    do i = 1, 700000
        r = r + twice(z)
    end do

    re = real(r, kind=c_float)
    im = aimag(r)
    if (abs(re - 7000000.0_c_float) > 1.0_c_float) error stop
    if (abs(im - 9800000.0_c_float) > 1.0_c_float) error stop
    print *, "PASSED"

end program bindc_11