Commit | Line | Data |
---|---|---|
7f918cf1 CE |
1 | (* Copyright (C) 2012,2013 Matthew Fluet. |
2 | * Copyright (C) 1999-2007 Henry Cejtin, Matthew Fluet, Suresh | |
3 | * Jagannathan, and Stephen Weeks. | |
4 | * Copyright (C) 1997-2000 NEC Research Institute. | |
5 | * | |
6 | * MLton is released under a BSD-style license. | |
7 | * See the file MLton-LICENSE for details. | |
8 | *) | |
9 | ||
10 | (* Primitive names are special -- see atoms/prim.fun. *) | |
11 | ||
12 | signature PRIM_REAL = | |
13 | sig | |
14 | type real | |
15 | type t = real | |
16 | ||
17 | val realSize: Primitive.Int32.int | |
18 | val exponentBias : Primitive.Int32.int | |
19 | val precision: Primitive.Int32.int | |
20 | val radix: Primitive.Int32.int | |
21 | ||
22 | structure Math : | |
23 | sig | |
24 | type real | |
25 | ||
26 | val acos: real -> real | |
27 | val asin: real -> real | |
28 | val atan: real -> real | |
29 | val atan2: real * real -> real | |
30 | val cos: real -> real | |
31 | val cosh: real -> real | |
32 | val e: real | |
33 | val exp: real -> real | |
34 | val ln: real -> real | |
35 | val log10: real -> real | |
36 | val pi: real | |
37 | val pow: real * real -> real | |
38 | val sin: real -> real | |
39 | val sinh: real -> real | |
40 | val sqrt: real -> real | |
41 | val tan: real -> real | |
42 | val tanh: real -> real | |
43 | end | |
44 | ||
45 | val * : real * real -> real | |
46 | val *+ : real * real * real -> real | |
47 | val *- : real * real * real -> real | |
48 | val + : real * real -> real | |
49 | val - : real * real -> real | |
50 | val / : real * real -> real | |
51 | val ~ : real -> real | |
52 | val < : real * real -> bool | |
53 | val <= : real * real -> bool | |
54 | val == : real * real -> bool | |
55 | val ?= : real * real -> bool | |
56 | val abs: real -> real | |
57 | val frexp: real * C_Int.t ref -> real | |
58 | val gdtoa: real * C_Int.t * C_Int.t * C_Int.t * C_Int.t ref -> C_String.t | |
59 | val ldexp: real * C_Int.t -> real | |
60 | val modf: real * real ref -> real | |
61 | val round: real -> real | |
62 | val realCeil: real -> real | |
63 | val realFloor: real -> real | |
64 | val realTrunc: real -> real | |
65 | val strtor: Primitive.NullString8.t * C_Int.t -> real | |
66 | ||
67 | (* Integer to float; depends on rounding mode. *) | |
68 | val fromInt8Unsafe: Primitive.Int8.int -> real | |
69 | val fromInt16Unsafe: Primitive.Int16.int -> real | |
70 | val fromInt32Unsafe: Primitive.Int32.int -> real | |
71 | val fromInt64Unsafe: Primitive.Int64.int -> real | |
72 | ||
73 | (* Float to float; depends on rounding mode. *) | |
74 | val fromReal32Unsafe: Primitive.Real32.real -> real | |
75 | val fromReal64Unsafe: Primitive.Real64.real -> real | |
76 | ||
77 | (* Word to float; depends on rounding mode. *) | |
78 | val fromWord8Unsafe: Primitive.Word8.word -> real | |
79 | val fromWord16Unsafe: Primitive.Word16.word -> real | |
80 | val fromWord32Unsafe: Primitive.Word32.word -> real | |
81 | val fromWord64Unsafe: Primitive.Word64.word -> real | |
82 | ||
83 | (* Float to integer, taking lowbits. *) | |
84 | val toInt8Unsafe: real -> Primitive.Int8.int | |
85 | val toInt16Unsafe: real -> Primitive.Int16.int | |
86 | val toInt32Unsafe: real -> Primitive.Int32.int | |
87 | val toInt64Unsafe: real -> Primitive.Int64.int | |
88 | ||
89 | (* Float to float; depends on rounding mode. *) | |
90 | val toReal32Unsafe: real -> Primitive.Real32.real | |
91 | val toReal64Unsafe: real -> Primitive.Real64.real | |
92 | ||
93 | (* Float to word, taking lowbits. *) | |
94 | val toWord8Unsafe: real -> Primitive.Word8.word | |
95 | val toWord16Unsafe: real -> Primitive.Word16.word | |
96 | val toWord32Unsafe: real -> Primitive.Word32.word | |
97 | val toWord64Unsafe: real -> Primitive.Word64.word | |
98 | end | |
99 | ||
100 | structure Primitive = struct | |
101 | ||
102 | open Primitive | |
103 | ||
104 | structure Real32 : PRIM_REAL = | |
105 | struct | |
106 | open Real32 | |
107 | ||
108 | val realSize : Int32.int = 32 | |
109 | val exponentBias : Int32.int = 127 | |
110 | val precision : Int32.int = 24 | |
111 | val radix : Int32.int = 2 | |
112 | ||
113 | structure Math = | |
114 | struct | |
115 | type real = real | |
116 | ||
117 | val acos = _prim "Real32_Math_acos": real -> real; | |
118 | val asin = _prim "Real32_Math_asin": real -> real; | |
119 | val atan = _prim "Real32_Math_atan": real -> real; | |
120 | val atan2 = _prim "Real32_Math_atan2": real * real -> real; | |
121 | val cos = _prim "Real32_Math_cos": real -> real; | |
122 | val cosh = _import "Real32_Math_cosh" private: real -> real; | |
123 | val e = #1 _symbol "Real32_Math_e" private: real GetSet.t; () | |
124 | val exp = _prim "Real32_Math_exp": real -> real; | |
125 | val ln = _prim "Real32_Math_ln": real -> real; | |
126 | val log10 = _prim "Real32_Math_log10": real -> real; | |
127 | val pi = #1 _symbol "Real32_Math_pi" private: real GetSet.t; () | |
128 | val pow = _import "Real32_Math_pow" private: real * real -> real; | |
129 | val sin = _prim "Real32_Math_sin": real -> real; | |
130 | val sinh = _import "Real32_Math_sinh" private: real -> real; | |
131 | val sqrt = _prim "Real32_Math_sqrt": real -> real; | |
132 | val tan = _prim "Real32_Math_tan": real -> real; | |
133 | val tanh = _import "Real32_Math_tanh" private: real -> real; | |
134 | end | |
135 | ||
136 | val * = _prim "Real32_mul": real * real -> real; | |
137 | val *+ = _prim "Real32_muladd": real * real * real -> real; | |
138 | val *- = _prim "Real32_mulsub": real * real * real -> real; | |
139 | val + = _prim "Real32_add": real * real -> real; | |
140 | val - = _prim "Real32_sub": real * real -> real; | |
141 | val / = _prim "Real32_div": real * real -> real; | |
142 | val ~ = _prim "Real32_neg": real -> real; | |
143 | val op < = _prim "Real32_lt": real * real -> bool; | |
144 | val op <= = _prim "Real32_le": real * real -> bool; | |
145 | val == = _prim "Real32_equal": real * real -> bool; | |
146 | val ?= = _prim "Real32_qequal": real * real -> bool; | |
147 | val abs = _prim "Real32_abs": real -> real; | |
148 | val frexp = _import "Real32_frexp" private: real * C_Int.t ref -> real; | |
149 | val gdtoa = _import "Real32_gdtoa" private: real * C_Int.t * C_Int.t * C_Int.t * C_Int.t ref -> C_String.t; | |
150 | val ldexp = _prim "Real32_ldexp": real * C_Int.t -> real; | |
151 | val modf = _import "Real32_modf" private: real * real ref -> real; | |
152 | val round = _prim "Real32_round": real -> real; | |
153 | val realCeil = _import "Real32_realCeil" private: real -> real; | |
154 | val realFloor = _import "Real32_realFloor" private: real -> real; | |
155 | val realTrunc = _import "Real32_realTrunc" private: real -> real; | |
156 | val strtor = _import "Real32_strtor" private: NullString8.t * C_Int.t -> real; | |
157 | ||
158 | val fromInt8Unsafe = _prim "WordS8_rndToReal32": Int8.int -> real; | |
159 | val fromInt16Unsafe = _prim "WordS16_rndToReal32": Int16.int -> real; | |
160 | val fromInt32Unsafe = _prim "WordS32_rndToReal32": Int32.int -> real; | |
161 | val fromInt64Unsafe = _prim "WordS64_rndToReal32": Int64.int -> real; | |
162 | ||
163 | val fromReal32Unsafe = _prim "Real32_rndToReal32": Real32.real -> real; | |
164 | val fromReal64Unsafe = _prim "Real64_rndToReal32": Real64.real -> real; | |
165 | ||
166 | val fromWord8Unsafe = _prim "WordU8_rndToReal32": Word8.word -> real; | |
167 | val fromWord16Unsafe = _prim "WordU16_rndToReal32": Word16.word -> real; | |
168 | val fromWord32Unsafe = _prim "WordU32_rndToReal32": Word32.word -> real; | |
169 | val fromWord64Unsafe = _prim "WordU64_rndToReal32": Word64.word -> real; | |
170 | ||
171 | val toInt8Unsafe = _prim "Real32_rndToWordS8": real -> Int8.int; | |
172 | val toInt16Unsafe = _prim "Real32_rndToWordS16": real -> Int16.int; | |
173 | val toInt32Unsafe = _prim "Real32_rndToWordS32": real -> Int32.int; | |
174 | val toInt64Unsafe = _prim "Real32_rndToWordS64": real -> Int64.int; | |
175 | ||
176 | val toReal32Unsafe = _prim "Real32_rndToReal32": real -> Real32.real; | |
177 | val toReal64Unsafe = _prim "Real32_rndToReal64": real -> Real64.real; | |
178 | ||
179 | val toWord8Unsafe = _prim "Real32_rndToWordU8": real -> Word8.word; | |
180 | val toWord16Unsafe = _prim "Real32_rndToWordU16": real -> Word16.word; | |
181 | val toWord32Unsafe = _prim "Real32_rndToWordU32": real -> Word32.word; | |
182 | val toWord64Unsafe = _prim "Real32_rndToWordU64": real -> Word64.word; | |
183 | end | |
184 | structure Real32 = | |
185 | struct | |
186 | open Real32 | |
187 | local | |
188 | structure S = RealComparisons (Real32) | |
189 | in | |
190 | open S | |
191 | end | |
192 | end | |
193 | ||
194 | structure Real64 : PRIM_REAL = | |
195 | struct | |
196 | open Real64 | |
197 | ||
198 | val realSize : Int32.int = 64 | |
199 | val exponentBias : Int32.int = 1023 | |
200 | val precision : Int32.int = 53 | |
201 | val radix : Int32.int = 2 | |
202 | ||
203 | structure Math = | |
204 | struct | |
205 | type real = real | |
206 | ||
207 | val acos = _prim "Real64_Math_acos": real -> real; | |
208 | val asin = _prim "Real64_Math_asin": real -> real; | |
209 | val atan = _prim "Real64_Math_atan": real -> real; | |
210 | val atan2 = _prim "Real64_Math_atan2": real * real -> real; | |
211 | val cos = _prim "Real64_Math_cos": real -> real; | |
212 | val cosh = _import "Real64_Math_cosh" private: real -> real; | |
213 | val e = #1 _symbol "Real64_Math_e" private: real GetSet.t; () | |
214 | val exp = _prim "Real64_Math_exp": real -> real; | |
215 | val ln = _prim "Real64_Math_ln": real -> real; | |
216 | val log10 = _prim "Real64_Math_log10": real -> real; | |
217 | val pi = #1 _symbol "Real64_Math_pi" private: real GetSet.t; () | |
218 | val pow = _import "Real64_Math_pow" private: real * real -> real; | |
219 | val sin = _prim "Real64_Math_sin": real -> real; | |
220 | val sinh = _import "Real64_Math_sinh" private: real -> real; | |
221 | val sqrt = _prim "Real64_Math_sqrt": real -> real; | |
222 | val tan = _prim "Real64_Math_tan": real -> real; | |
223 | val tanh = _import "Real64_Math_tanh" private: real -> real; | |
224 | end | |
225 | ||
226 | val * = _prim "Real64_mul": real * real -> real; | |
227 | val *+ = _prim "Real64_muladd": real * real * real -> real; | |
228 | val *- = _prim "Real64_mulsub": real * real * real -> real; | |
229 | val + = _prim "Real64_add": real * real -> real; | |
230 | val - = _prim "Real64_sub": real * real -> real; | |
231 | val / = _prim "Real64_div": real * real -> real; | |
232 | val ~ = _prim "Real64_neg": real -> real; | |
233 | val op < = _prim "Real64_lt": real * real -> bool; | |
234 | val op <= = _prim "Real64_le": real * real -> bool; | |
235 | val == = _prim "Real64_equal": real * real -> bool; | |
236 | val ?= = _prim "Real64_qequal": real * real -> bool; | |
237 | val abs = _prim "Real64_abs": real -> real; | |
238 | val frexp = _import "Real64_frexp" private: real * C_Int.t ref -> real; | |
239 | val gdtoa = _import "Real64_gdtoa" private: real * C_Int.t * C_Int.t * C_Int.t * C_Int.t ref -> C_String.t; | |
240 | val ldexp = _prim "Real64_ldexp": real * C_Int.t -> real; | |
241 | val modf = _import "Real64_modf" private: real * real ref -> real; | |
242 | val round = _prim "Real64_round": real -> real; | |
243 | val realCeil = _import "Real64_realCeil" private: real -> real; | |
244 | val realFloor = _import "Real64_realFloor" private: real -> real; | |
245 | val realTrunc = _import "Real64_realTrunc" private: real -> real; | |
246 | val strtor = _import "Real64_strtor" private: NullString8.t * C_Int.t -> real; | |
247 | ||
248 | val fromInt8Unsafe = _prim "WordS8_rndToReal64": Int8.int -> real; | |
249 | val fromInt16Unsafe = _prim "WordS16_rndToReal64": Int16.int -> real; | |
250 | val fromInt32Unsafe = _prim "WordS32_rndToReal64": Int32.int -> real; | |
251 | val fromInt64Unsafe = _prim "WordS64_rndToReal64": Int64.int -> real; | |
252 | ||
253 | val fromReal32Unsafe = _prim "Real32_rndToReal64": Real32.real -> real; | |
254 | val fromReal64Unsafe = _prim "Real64_rndToReal64": Real64.real -> real; | |
255 | ||
256 | val fromWord8Unsafe = _prim "WordU8_rndToReal64": Word8.word -> real; | |
257 | val fromWord16Unsafe = _prim "WordU16_rndToReal64": Word16.word -> real; | |
258 | val fromWord32Unsafe = _prim "WordU32_rndToReal64": Word32.word -> real; | |
259 | val fromWord64Unsafe = _prim "WordU64_rndToReal64": Word64.word -> real; | |
260 | ||
261 | val toInt8Unsafe = _prim "Real64_rndToWordS8": real -> Int8.int; | |
262 | val toInt16Unsafe = _prim "Real64_rndToWordS16": real -> Int16.int; | |
263 | val toInt32Unsafe = _prim "Real64_rndToWordS32": real -> Int32.int; | |
264 | val toInt64Unsafe = _prim "Real64_rndToWordS64": real -> Int64.int; | |
265 | ||
266 | val toReal32Unsafe = _prim "Real64_rndToReal32": real -> Real32.real; | |
267 | val toReal64Unsafe = _prim "Real64_rndToReal64": real -> Real64.real; | |
268 | ||
269 | val toWord8Unsafe = _prim "Real64_rndToWordU8": real -> Word8.word; | |
270 | val toWord16Unsafe = _prim "Real64_rndToWordU16": real -> Word16.word; | |
271 | val toWord32Unsafe = _prim "Real64_rndToWordU32": real -> Word32.word; | |
272 | val toWord64Unsafe = _prim "Real64_rndToWordU64": real -> Word64.word; | |
273 | end | |
274 | structure Real64 = | |
275 | struct | |
276 | open Real64 | |
277 | local | |
278 | structure S = RealComparisons (Real64) | |
279 | in | |
280 | open S | |
281 | end | |
282 | end | |
283 | ||
284 | end |