-
Notifications
You must be signed in to change notification settings - Fork 9
/
gnumber.dats
167 lines (157 loc) · 2.81 KB
/
gnumber.dats
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
(* ****** ****** *)
//
// For use in INT2PROGINATS
//
(* ****** ****** *)
//
// Generic Operations on Numbers
//
(* ****** ****** *)
//
#include
"share/atspre_staload.hats"
//
(* ****** ****** *)
//
extern
fun fact(n: int): int
//
(*
implement
fact(n) =
if n > 0 then n * fact(n-1) else 1
// end of [fact]
*)
(* ****** ****** *)
//
extern
fun factd(n: int): double
//
(*
implement
factd(n) =
if n > 0 then n * factd(n-1) else 1.0
// end of [factd]
*)
(* ****** ****** *)
extern
fun{a:t@ype} gfact(n: int): a
implement
{a}(*tmp*)
gfact(n) = (
//
if n > 0
then gmul_int_val<a>(n, gfact<a>(n-1))
else gnumber_int<a>(1)
//
) (* end of [gfact] *)
(* ****** ****** *)
implement
{a}(*tmp*)
gfact(n) = let
//
overload * with gmul_int_val
//
in
//
if n > 0
then n * gfact<a>(n-1) else gnumber_int<a>(1)
//
end (* end of [gfact] *)
(* ****** ****** *)
implement fact(n) = gfact<int>(n)
implement factd(n) = gfact<double>(n)
(* ****** ****** *)
//
val () =
println! ("fact(10) = ", fact(10))
val () =
println! ("fact(34) = ", fact(34))
val () =
println! ("fact(100) = ", fact(100))
//
val () =
println! ("factd(10) = ", factd(10))
val () =
println! ("factd(34) = ", factd(34))
val () =
println! ("factd(100) = ", factd(100))
//
val () =
println! ("gfact<int>(10) = ", gfact<int>(10))
val () =
println! ("gfact<int>(34) = ", gfact<int>(34))
val () =
println! ("gfact<int>(100) = ", gfact<int>(100))
//
val () =
println! ("gfact<lint>(10) = ", gfact<lint>(10))
val () =
println! ("gfact<lint>(34) = ", gfact<lint>(34))
val () =
println! ("gfact<lint>(100) = ", gfact<lint>(100))
//
val () =
println! ("gfact<llint>(10) = ", gfact<llint>(10))
val () =
println! ("gfact<llint>(34) = ", gfact<llint>(34))
val () =
println! ("gfact<llint>(100) = ", gfact<llint>(100))
//
val () =
println! ("gfact<float>(10) = ", gfact<float>(10))
val () =
println! ("gfact<float>(34) = ", gfact<float>(34))
val () =
println! ("gfact<float>(100) = ", gfact<float>(100))
//
val () =
println! ("gfact<double>(10) = ", gfact<double>(10))
val () =
println! ("gfact<double>(34) = ", gfact<double>(34))
val () =
println! ("gfact<double>(100) = ", gfact<double>(100))
//
(* ****** ****** *)
//
#define
HX_INTINF_targetloc
"$PATSHOME/contrib\
/atscntrb/atscntrb-hx-intinf"
//
(* ****** ****** *)
//
staload _(*T*) =
"{$HX_INTINF}/DATS/intinf_t.dats"
staload _(*VT*) =
"{$HX_INTINF}/DATS/intinf_vt.dats"
//
staload
GINTINF =
"{$HX_INTINF}/DATS/gintinf_t.dats"
//
(* ****** ****** *)
//
typedef
intinf = $GINTINF.intinf
//
overload
print with $GINTINF.print_intinf
//
(* ****** ****** *)
//
val () =
println!
(
"gfact<intinf>(10) = ", gfact<intinf>(10)
) (* println! *)
//
val () =
println! ("gfact<intinf>(34) = ", gfact<intinf>(34))
val () =
println! ("gfact<intinf>(100) = ", gfact<intinf>(100))
//
(* ****** ****** *)
implement main0((*void*)) = ()
(* ****** ****** *)
(* end of [gnumber.dats] *)