forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJs_float.html
461 lines (359 loc) · 21.6 KB
/
Js_float.html
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="../api_static/tomorrow-night.css">
<link rel="stylesheet" href="../api_static/style.css" type="text/css">
<script src="../api_static//highlight.pack.js"></script>
<script src="../api_static//script.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<meta charset="utf8">
<link rel="previous" href="Js_exn.html"><link rel="next" href="Js_global.html">
<title> Js_float </title></head>
<body>
<nav class="module-index"><ul><li><a href="Bs.html">Bs</a></li>
<li><a href="Bs_dyn.html">Bs_dyn</a></li>
<li><a href="Bs_dyn_lib.html">Bs_dyn_lib</a></li>
<li><a href="Dom.html">Dom</a></li>
<li><a href="Dom_storage.html">Dom_storage</a></li>
<li><a href="Js.html">Js</a></li>
<li><a href="Js_array.html">Js_array</a></li>
<li><a href="Js_boolean.html">Js_boolean</a></li>
<li><a href="Js_cast.html">Js_cast</a></li>
<li><a href="Js_date.html">Js_date</a></li>
<li><a href="Js_dict.html">Js_dict</a></li>
<li><a href="Js_exn.html">Js_exn</a></li>
<li><a href="Js_float.html">Js_float</a></li>
<li><a href="Js_global.html">Js_global</a></li>
<li><a href="Js_int.html">Js_int</a></li>
<li><a href="Js_int64.html">Js_int64</a></li>
<li><a href="Js_internal.html">Js_internal</a></li>
<li><a href="Js_json.html">Js_json</a></li>
<li><a href="Js_list.html">Js_list</a></li>
<li><a href="Js_math.html">Js_math</a></li>
<li><a href="Js_nativeint.html">Js_nativeint</a></li>
<li><a href="Js_null.html">Js_null</a></li>
<li><a href="Js_null_undefined.html">Js_null_undefined</a></li>
<li><a href="Js_obj.html">Js_obj</a></li>
<li><a href="Js_option.html">Js_option</a></li>
<li><a href="Js_primitive.html">Js_primitive</a></li>
<li><a href="Js_promise.html">Js_promise</a></li>
<li><a href="Js_re.html">Js_re</a></li>
<li><a href="Js_result.html">Js_result</a></li>
<li><a href="Js_string.html">Js_string</a></li>
<li><a href="Js_typed_array.html">Js_typed_array</a></li>
<li><a href="Js_types.html">Js_types</a></li>
<li><a href="Js_undefined.html">Js_undefined</a></li>
<li><a href="Js_unsafe.html">Js_unsafe</a></li>
<li><a href="Js_vector.html">Js_vector</a></li>
<li><a href="Node.html">Node</a></li>
<li><a href="Node_buffer.html">Node_buffer</a></li>
<li><a href="Node_child_process.html">Node_child_process</a></li>
<li><a href="Node_fs.html">Node_fs</a></li>
<li><a href="Node_module.html">Node_module</a></li>
<li><a href="Node_path.html">Node_path</a></li>
<li><a href="Node_process.html">Node_process</a></li></ul></nav>
<div class="navbar"><a class="pre" href="Js_exn.html" title="Js_exn">Previous</a>
<a class="up" href="index.html" title="Index">Up</a>
<a class="post" href="Js_global.html" title="Js_global">Next</a>
</div>
<h1>Module <a href="type_Js_float.html">Js_float</a></h1>
<pre><span class="keyword">module</span> Js_float: <code class="code">sig</code> <a href="Js_float.html">..</a> <code class="code">end</code></pre><div class="info module top">
<div class="not-examples">
Provides functions for inspecting and manipulating <code class="code">float</code>s<br>
</div>
</div>
<hr width="100%">
<pre><span id="VAL_NaN"><span class="keyword">val</span> _NaN</span> : <code class="type">float</code></pre><div class="info ">
<div class="not-examples">
The special value "Not a Number"<br>
<div class="tag"> <b>See also</b> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN">MDN</a><br>
</div>
</div>
</div>
<pre><span id="VALisNaN"><span class="keyword">val</span> isNaN</span> : <code class="type">float -> bool</code></pre><div class="info ">
<div class="not-examples">
Tests if the given value is <code class="code">_NaN</code>
<p>
Note that both <code class="code">_NaN = _NaN</code> and <code class="code">_NaN == _NaN</code> will return <code class="code">false</code>. <code class="code">isNaN</code> is
therefore necessary to test for <code class="code">_NaN</code>.
<p>
<b>Returns</b> <code class="code">true</code> if the given value is <code class="code">_NaN</code>, <code class="code">false</code> otherwise<br>
<div class="tag"> <b>See also</b> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN">MDN</a><br>
</div>
</div>
</div>
<pre><span id="VALisFinite"><span class="keyword">val</span> isFinite</span> : <code class="type">float -> bool</code></pre><div class="info ">
<div class="not-examples">
Tests if the given value is finite
<p>
<b>Returns</b> <code class="code">true</code> if the given value is a finite number, <code class="code">false</code> otherwise<br>
<div class="tag"> <b>See also</b> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite">MDN</a><br>
</div>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code">(* returns [false] *)
let _ = Js.Float.isFinite infinity
(* returns [false] *)
let _ = Js.Float.isFinite neg_infinity
(* returns [false] *)
let _ = Js.Float.isFinite _NaN
(* returns [true] *)
let _ = Js.Float.isFinite 1234
</code></pre> </pre>
</div>
</div>
<pre><span id="VALtoExponential"><span class="keyword">val</span> toExponential</span> : <code class="type">float -> string</code></pre><div class="info ">
<div class="not-examples">
Formats a <code class="code">float</code> using exponential (scientific) notation
<p>
<b>Returns</b> a <code class="code">string</code> representing the given value in exponential notation<br>
<div class="tag"> <b>Raises</b> <code>RangeError</code> if digits is not in the range [0, 20] (inclusive)<br>
</div><div class="tag"> <b>See also</b> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential">MDN</a><br>
</div>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code">(* prints "7.71234e+1" *)
let _ = Js.log @@ Js.Float.toExponential 77.1234
(* prints "7.7e+1" *)
let _ = Js.log @@ Js.Float.toExponential 77.
</code></pre> </pre>
</div>
</div>
<pre><span id="VALtoExponentialWithPrecision"><span class="keyword">val</span> toExponentialWithPrecision</span> : <code class="type">float -> digits:int -> string</code></pre><div class="info ">
<div class="not-examples">
Formats a <code class="code">float</code> using exponential (scientific) notation
<p>
<b>digits</b> specifies how many digits should appear after the decimal point. The
value must be in the range [0, 20] (inclusive).
<p>
<b>Returns</b> a <code class="code">string</code> representing the given value in exponential notation
<p>
The output will be rounded or padded with zeroes if necessary.<br>
<div class="tag"> <b>Raises</b> <code>RangeError</code> if digits is not in the range [0, 20] (inclusive)<br>
</div><div class="tag"> <b>See also</b> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential">MDN</a><br>
</div>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code">(* prints "7.71e+1" *)
let _ = Js.log @@ Js.Float.toExponentialWithPrecision 77.1234 ~digits:2
</code></pre> </pre>
</div>
</div>
<pre><span id="VALtoFixed"><span class="keyword">val</span> toFixed</span> : <code class="type">float -> string</code></pre><div class="info ">
<div class="not-examples">
Formats a <code class="code">float</code> using fixed point notation
<p>
<b>Returns</b> a <code class="code">string</code> representing the given value in fixed-point notation (usually)<br>
<div class="tag"> <b>Raises</b> <code>RangeError</code> if digits is not in the range [0, 20] (inclusive)<br>
</div><div class="tag"> <b>See also</b> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed">MDN</a><br>
</div>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code">(* prints "12346" (note the rounding) *)
let _ = Js.log @@ Js.Float.toFixed 12345.6789
(* print "1.2e+21" *)
let _ = Js.log @@ Js.Float.toFixed 1.2e21
</code></pre> </pre>
</div>
</div>
<pre><span id="VALtoFixedWithPrecision"><span class="keyword">val</span> toFixedWithPrecision</span> : <code class="type">float -> digits:int -> string</code></pre><div class="info ">
<div class="not-examples">
Formats a <code class="code">float</code> using fixed point notation
<p>
<b>digits</b> specifies how many digits should appear after the decimal point. The
value must be in the range [0, 20] (inclusive). Defaults to <code class="code">0</code>.
<p>
<b>Returns</b> a <code class="code">string</code> representing the given value in fixed-point notation (usually)
<p>
The output will be rounded or padded with zeroes if necessary.<br>
<div class="tag"> <b>Raises</b> <code>RangeError</code> if digits is not in the range [0, 20] (inclusive)<br>
</div><div class="tag"> <b>See also</b> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed">MDN</a><br>
</div>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code">(* prints "12345.7" (note the rounding) *)
let _ = Js.log @@ Js.Float.toFixedWithPrecision 12345.6789 ~digits:1
(* prints "0.00" (note the added zeroes) *)
let _ = Js.log @@ Js.Float.toFixedWithPrecision 0. ~digits:2
</code></pre> </pre>
</div>
</div>
<pre><span id="VALtoPrecision"><span class="keyword">val</span> toPrecision</span> : <code class="type">float -> string</code></pre><div class="info ">
<div class="not-examples">
Formats a <code class="code">float</code> using some fairly arbitrary rules
<p>
<b>Returns</b> a <code class="code">string</code> representing the given value in fixed-point (usually)
<p>
<code class="code">toPrecision</code> differs from <code class="code">toFixed</code> in that the former will format the number
with full precision, while the latter will not output any digits after the
decimal point.<br>
<div class="tag"> <b>Raises</b> <code>RangeError</code> if digits is not in the range accepted by this function (what do you mean "vague"?)<br>
</div><div class="tag"> <b>See also</b> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision">MDN</a><br>
</div>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code">(* prints "12345.6789" *)
let _ = Js.log @@ Js.Float.toPrecision 12345.6789
(* print "1.2e+21" *)
let _ = Js.log @@ Js.Float.toPrecision 1.2e21
</code></pre> </pre>
</div>
</div>
<pre><span id="VALtoPrecisionWithPrecision"><span class="keyword">val</span> toPrecisionWithPrecision</span> : <code class="type">float -> digits:int -> string</code></pre><div class="info ">
<div class="not-examples">
Formats a <code class="code">float</code> using some fairly arbitrary rules
<p>
<b>digits</b> specifies how many digits should appear in total. The
value must between 0 and some arbitrary number that's hopefully at least larger
than 20 (for Node it's 21. Why? Who knows).
<p>
<b>Returns</b> a <code class="code">string</code> representing the given value in fixed-point or scientific notation
<p>
The output will be rounded or padded with zeroes if necessary.
<p>
<code class="code">toPrecisionWithPrecision</code> differs from <code class="code">toFixedWithPrecision</code> in that the former
will count all digits against the precision, while the latter will count only
the digits after the decimal point. <code class="code">toPrecisionWithPrecision</code> will also use
scientific notation if the specified precision is less than the number for digits
before the decimal point.<br>
<div class="tag"> <b>Raises</b> <code>RangeError</code> if digits is not in the range accepted by this function (what do you mean "vague"?)<br>
</div><div class="tag"> <b>See also</b> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision">MDN</a><br>
</div>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code">(* prints "1e+4" *)
let _ = Js.log @@ Js.Float.toPrecisionWithPrecision 12345.6789 ~digits:1
(* prints "0.0" *)
let _ = Js.log @@ Js.Float.toPrecisionWithPrecision 0. ~digits:2
</code></pre> </pre>
</div>
</div>
<pre><span id="VALtoString"><span class="keyword">val</span> toString</span> : <code class="type">float -> string</code></pre><div class="info ">
<div class="not-examples">
Formats a <code class="code">float</code> as a string
<p>
<b>Returns</b> a <code class="code">string</code> representing the given value in fixed-point (usually)<br>
<div class="tag"> <b>See also</b> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString">MDN</a><br>
</div>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code">(* prints "12345.6789" *)
let _ = Js.log @@ Js.Float.toString 12345.6789
</code></pre> </pre>
</div>
</div>
<pre><span id="VALtoStringWithRadix"><span class="keyword">val</span> toStringWithRadix</span> : <code class="type">float -> radix:int -> string</code></pre><div class="info ">
<div class="not-examples">
Formats a <code class="code">float</code> as a string
<p>
<b>radix</b> specifies the radix base to use for the formatted number. The
value must be in the range [2, 36] (inclusive).
<p>
<b>Returns</b> a <code class="code">string</code> representing the given value in fixed-point (usually)<br>
<div class="tag"> <b>Raises</b> <code>RangeError</code> if radix is not in the range [2, 36] (inclusive)<br>
</div><div class="tag"> <b>See also</b> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString">MDN</a><br>
</div>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code">(* prints "110" *)
let _ = Js.log @@ Js.Float.toStringWithRadix 6. ~radix:2
(* prints "11.001000111101011100001010001111010111000010100011111" *)
let _ = Js.log @@ Js.Float.toStringWithRadix 3.14 ~radix:2
(* prints "deadbeef" *)
let _ = Js.log @@ Js.Float.toStringWithRadix 3735928559. ~radix:16
(* prints "3f.gez4w97ry0a18ymf6qadcxr" *)
let _ = Js.log @@ Js.Float.toStringWithRadix 123.456 ~radix:36
</code></pre> </pre>
</div>
</div>
<pre><span id="VALfromString"><span class="keyword">val</span> fromString</span> : <code class="type">string -> float</code></pre><div class="info ">
<div class="not-examples">
Parses the given <code class="code">string</code> into a <code class="code">float</code> using JavaScript semantics
<p>
<b>Returns</b> the number as a <code class="code">float</code> if successfully parsed, <code class="code">_NaN</code> otherwise.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code">(* returns 123 *)
let _ = Js.Float.fromString "123"
(* returns 12.3 *)
let _ = Js.Float.fromString "12.3"
(* returns 0 *)
let _ = Js.Float.fromString ""
(* returns 17 *)
let _ = Js.Float.fromString "0x11"
(* returns 3 *)
let _ = Js.Float.fromString "0b11"
(* returns 9 *)
let _ = Js.Float.fromString "0o11"
(* returns [_NaN] *)
let _ = Js.Float.fromString "foo"
(* returns [_NaN] *)
let _ = Js.Float.fromString "100a"
</code></pre> </pre>
</div>
</div>
<pre><span id="VALnan"><span class="keyword">val</span> nan</span> : <code class="type">float</code></pre><div class="info ">
<div class="not-examples">
<div class="warning">
<span class="label">Deprecated.</span>
Use <a href="Js_float.html#VAL_NaN"><code class="code">Js_float._NaN</code></a> instead
</div>
</div>
</div>
<pre><span id="VALto_exponential"><span class="keyword">val</span> to_exponential</span> : <code class="type">float -> prec:int -> string</code></pre><div class="info ">
<div class="not-examples">
<div class="warning">
<span class="label">Deprecated.</span>
Use <a href="Js_float.html#VALtoExponential"><code class="code">Js_float.toExponential</code></a> instead
</div>
</div>
</div>
<pre><span id="VALexp"><span class="keyword">val</span> exp</span> : <code class="type">float -> float</code></pre><div class="info ">
<div class="not-examples">
<div class="warning">
<span class="label">Deprecated.</span>
Use <code class="code">exp</code> in <a href="Js.Math.html"><code class="code">Js.Math</code></a> instead
</div>
</div>
</div>
<pre><span id="VALlog"><span class="keyword">val</span> log</span> : <code class="type">float -> float</code></pre><div class="info ">
<div class="not-examples">
<div class="warning">
<span class="label">Deprecated.</span>
Use <code class="code">log</code> in <a href="Js.Math.html"><code class="code">Js.Math</code></a> instead
</div>
</div>
</div>
<pre><span id="VALlog2"><span class="keyword">val</span> log2</span> : <code class="type">float</code></pre><div class="info ">
<div class="not-examples">
<div class="warning">
<span class="label">Deprecated.</span>
Use <code class="code">_LN2</code> in <a href="Js.Math.html"><code class="code">Js.Math</code></a> instead
</div>
</div>
</div>
<pre><span id="VALmax"><span class="keyword">val</span> max</span> : <code class="type">float -> float -> float</code></pre><div class="info ">
<div class="not-examples">
<div class="warning">
<span class="label">Deprecated.</span>
Use <code class="code">max_float</code> in <a href="Js.Math.html"><code class="code">Js.Math</code></a> instead
</div>
</div>
</div>
<pre><span id="VALrandom"><span class="keyword">val</span> random</span> : <code class="type">unit -> float</code></pre><div class="info ">
<div class="not-examples">
<div class="warning">
<span class="label">Deprecated.</span>
Use <code class="code">random</code> in <a href="Js.Math.html"><code class="code">Js.Math</code></a> instead
</div>
</div>
</div>
<pre><span id="VALof_any"><span class="keyword">val</span> of_any</span> : <code class="type">'a -> float</code></pre><div class="info ">
<div class="not-examples">
<div class="warning">
<span class="label">Deprecated.</span>
This is an unsafe function, please use a proper conversion function
</div>
</div>
</div>
</body></html>