Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

Testing latest pari + WASM + node.js... and it works?! Wow.

28495 views
License: GPL3
ubuntu2004
1
! Example program that shows how to create FORTRAN binding for PARI
2
module PARI
3
use ISO_C_BINDING, only : C_LONG, C_DOUBLE, C_PTR
4
interface
5
subroutine pari_init(parisize, maxprime) bind(C,name='pari_init')
6
import C_LONG
7
integer(kind=C_LONG), VALUE :: parisize
8
integer(kind=C_LONG), VALUE :: maxprime
9
end subroutine pari_init
10
!
11
subroutine pari_close() bind(C,name='pari_close')
12
end subroutine pari_close
13
!
14
type(C_PTR) function dbltor( r ) bind(C,name='dbltor')
15
import C_DOUBLE, C_PTR
16
real(kind=C_DOUBLE), VALUE :: r
17
end function dbltor
18
!
19
real(kind=C_DOUBLE) function rtodbl( x ) bind(C,name='rtodbl')
20
import C_DOUBLE, C_PTR
21
type(C_PTR), VALUE :: x
22
end function rtodbl
23
!
24
type(C_PTR) function gsqr( x ) bind(C,name='gsqr')
25
import C_PTR
26
type(C_PTR), VALUE :: x
27
end function gsqr
28
!
29
type(C_PTR) function gmul( x , y) bind(C,name='gmul')
30
import C_PTR
31
type(C_PTR), VALUE :: x
32
type(C_PTR), VALUE :: y
33
end function gmul
34
!
35
type(C_PTR) function gprec( x , d) bind(C,name='gprec')
36
import C_PTR, C_LONG
37
type(C_PTR), VALUE :: x
38
integer(kind=C_LONG), VALUE :: d
39
end function gprec
40
!
41
type(C_PTR) function gmod( x , y) bind(C,name='gmod')
42
import C_PTR
43
type(C_PTR), VALUE :: x
44
type(C_PTR), VALUE :: y
45
end function gmod
46
!
47
type(C_PTR) function glog( x , prec) bind(C,name='glog')
48
import C_PTR, C_LONG
49
type(C_PTR), VALUE :: x
50
integer(kind=C_LONG), VALUE :: prec
51
end function glog
52
!
53
type(C_PTR) function stoi(x) bind(C,name='stoi')
54
import C_PTR, C_LONG
55
integer(kind=C_LONG), VALUE :: x
56
end function stoi
57
!
58
integer(kind=C_LONG) function itos(x) bind(C,name='itos')
59
import C_PTR, C_LONG
60
type(C_PTR), VALUE :: x
61
end function itos
62
!
63
type(C_PTR) function Pi2n(x, prec) bind(C,name='Pi2n')
64
import C_PTR, C_LONG
65
integer(kind=C_LONG), VALUE :: x
66
integer(kind=C_LONG), VALUE :: prec
67
end function Pi2n
68
end interface
69
end module PARI
70
!
71
PROGRAM prog
72
use ISO_C_BINDING, only : C_PTR, C_DOUBLE
73
use PARI
74
implicit none
75
real(kind=C_DOUBLE) :: r = 1e36
76
type(C_PTR) :: p
77
integer(kind=C_LONG) :: prec = 20 ! 18 words
78
CALL pari_init(10000000_8,2_8)
79
p = glog(stoi(10000_8),prec)
80
p = gmod(p, Pi2n(1_8, prec))
81
r = rtodbl(p)
82
CALL pari_close()
83
PRINT '(a,f0.9)','log(10000)%(2*Pi) = ', r
84
END PROGRAM prog
85
86