-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathCore__Float.resi
368 lines (291 loc) · 10 KB
/
Core__Float.resi
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
/* Copyright (C) 2015-2016 Bloomberg Finance L.P.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* In addition to the permissions granted to you by the LGPL, you may combine
* or link a "work that uses the Library" with a publicly distributed version
* of this file to produce a combined library or application, then distribute
* that combined work under the terms of your choosing, with no requirement
* to comply with the obligations normally placed on you by section 4 of the
* LGPL version 3 (or the corresponding section of a later version of the LGPL
* should you choose to use a later version).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/***
Functions for interacting with float.
*/
/**
Float constants.
*/
module Constants: {
/**
The special value "Not a Number"
See [`NaN`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN) on MDN.
## Examples
```rescript
Float.Constants.nan
```
*/
@val
external nan: float = "NaN"
/**
Represents the difference between 1 and the smallest floating point number greater than 1.
See [`Number.EPSILON`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/EPSILON) on MDN.
## Examples
```rescript
Float.Constants.epsilon
```
*/
@val
external epsilon: float = "Number.EPSILON"
/**
The positive Infinity value
See [`Number.POSITIVE_INFINITY`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/POSITIVE_INFINITY) on MDN.
## Examples
```rescript
Float.Constants.positiveInfinity
```
*/
@val
external positiveInfinity: float = "Number.POSITIVE_INFINITY"
/**
The negative Infinity value
See [`Number.NEGATIVE_INFINITY`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/NEGATIVE_INFINITY) on MDN.
## Examples
```rescript
Float.Constants.negativeInfinity
```
*/
@val
external negativeInfinity: float = "Number.NEGATIVE_INFINITY"
/**
The smallest positive numeric value representable in JavaScript.
See [`Number.MIN_VALUE`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_VALUE) on MDN.
## Examples
```rescript
Float.Constants.minValue
```
*/
@val
external minValue: float = "Number.MIN_VALUE"
/**
The maximum positive numeric value representable in JavaScript.
See [`Number.MAX_VALUE`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_VALUE) on MDN.
## Examples
```rescript
Float.Constants.minValue
```
*/
@val
external maxValue: float = "Number.MAX_VALUE"
}
/**
`isNaN(v)` tests if the given `v` is `NaN`.
See [`NaN`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN) on MDN.
## Examples
```rescript
Float.isNaN(3.0) // false
Float.isNaN(Float.Constants.nan) // true
```
*/
@val
external isNaN: float => bool = "isNaN"
/**
`isFinite(v)` tests if the given `v` is finite.
See [`isFinite`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isFinite) on MDN.
## Examples
```rescript
Float.isFinite(1.0) // true
Float.isFinite(Float.Constants.nan) // false
Float.isFinite(Float.Constants.positiveInfinity) // false
```
*/
@val
external isFinite: float => bool = "isFinite"
/**
`parseFloat(v)` parse the given `v` and returns a float. Leading whitespace in
`v` is ignored. Returns `NaN` if `v` can't be parsed. Use [`fromString`] to
ensure it returns a valid float and not `NaN`.
See [`parseFloat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat) on MDN.
## Examples
```rescript
Float.parseFloat("1.0") // 1.0
Float.parseFloat(" 3.14 ") // 3.14
Float.parseFloat(3.0) // 3.0
Float.parseFloat("3.14some non-digit characters") // 3.14
Float.parseFloat("error")->Float.isNaN // true
```
*/
@val
external parseFloat: string => float = "parseFloat"
/**
`toExponential(v)` return a `string` representing the given value in exponential
notation.
See [`Number.toExponential`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential) on MDN.
## Examples
```rescript
Float.toExponential(1000.0) // "1e+3"
Float.toExponential(-1000.0) // "-1e+3"
```
*/
@send
external toExponential: float => string = "toExponential"
/**
`toExponential(v, ~digits)` return a `string` representing the given value in
exponential notation. `digits` specifies how many digits should appear after
the decimal point.
See [`Number.toExponential`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential) on MDN.
## Examples
```rescript
Float.toExponentialWithPrecision(77.0, ~digits=2) // "7.70e+1"
Float.toExponentialWithPrecision(5678.0, ~digits=2) // "5.68e+3"
```
## Exceptions
- `RangeError`: If `digits` less than 0 or greater than 10.
*/
@send
external toExponentialWithPrecision: (float, ~digits: int) => string = "toExponential"
/**
`toFixed(v)` return a `string` representing the given value using fixed-point
notation.
See [`Number.toFixed`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed) on MDN.
## Examples
```rescript
Float.toFixed(123456.0) // "123456.00"
Float.toFixed(10.0) // "10.00"
```
*/
@send
external toFixed: float => string = "toFixed"
/**
`toFixedWithPrecision(v, ~digits)` return a `string` representing the given
value using fixed-point notation. `digits` specifies how many digits should
appear after the decimal point.
See [`Number.toFixed`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed) on MDN.
## Examples
```rescript
Float.toFixed(300.0, ~digits=4) // "300.0000"
Float.toFixed(300.0, ~digits=1) // "300.0"
```
## Exceptions
- `RangeError`: If `digits` is less than 0 or larger than 100.
*/
@send
external toFixedWithPrecision: (float, ~digits: int) => string = "toFixed"
/**
`toPrecision(v)` return a `string` representing the giver value with precision.
This function omits the argument that controls precision, so it behaves like
`toString`. See `toPrecisionWithPrecision` to control precision.
See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.
## Examples
```rescript
Float.toPrecision(100.0) // "100"
Float.toPrecision(1.0) // "1"
```
*/
@send
external toPrecision: float => string = "toPrecision"
/**
`toPrecision(v, ~digits)` return a `string` representing the giver value with
precision. `digits` specifies the number of significant digits.
See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.
## Examples
```rescript
Float.toPrecision(100.0, ~digits=2) // "1.0e+2"
Float.toPrecision(1.0) // "1.0"
```
## Exceptions
- `RangeError`: If `digits` is not between 1 and 100 (inclusive).
Implementations are allowed to support larger and smaller values as well.
ECMA-262 only requires a precision of up to 21 significant digits.
*/
@send
external toPrecisionWithPrecision: (float, ~digits: int) => string = "toPrecision"
/**
`toString(v)` return a `string` representing the given value.
See [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString) on MDN.
## Examples
```rescript
Float.toString(1000.0) // "1000"
Float.toString(-1000.0) // "-1000"
```
*/
@send
external toString: float => string = "toString"
/**
`toStringWithRadix(v, ~radix)` return a `string` representing the given value.
`~radix` specifies the radix base to use for the formatted number.
See [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString) on MDN.
## Examples
```rescript
Float.toString(6.0, ~radix=2) // "110"
Float.toString(3735928559.0, ~radix=16) // "deadbeef"
Float.toStringWithRadix(123456.0, ~radix=36) // "2n9c"
```
## Exceptions
`RangeError`: if `radix` is less than 2 or greater than 36.
*/
@send
external toStringWithRadix: (float, ~radix: int) => string = "toString"
/**
`toLocaleString(v)` return a `string` with language-sensitive representing the
given value.
See [`Number.toLocaleString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString) on MDN.
## Examples
```rescript
// If the application uses English as the default language
Int.toLocaleString(1000.0) // "1,000"
// If the application uses Portuguese Brazil as the default language
Int.toLocaleString(1000.0) // "1.000"
```
*/
@send
external toLocaleString: float => string = "toLocaleString"
/**
`fromString(str)` return an `option<int>` representing the given value `str`.
## Examples
```rescript
Float.fromString("0") == Some(0.0)
Float.fromString("NaN") == None
Float.fromString("6") == Some(6.0)
```
*/
let fromString: string => option<float>
/**
`toInt(v)` returns an int to given float `v`.
## Examples
```rescript
Float.toInt(2.0) == 2
Float.toInt(1.0) == 1
Float.toInt(1.1) == 1
Float.toInt(1.6) == 1
```
*/
external toInt: float => int = "%intoffloat"
/**
`fromInt(v)` returns a float to given int `v`.
## Examples
```rescript
Float.fromInt(2) == 2.0
Float.fromInt(1) == 1.0
```
*/
external fromInt: int => float = "%identity"
/**
`mod(n1, n2)` calculates the modulo (remainder after division) of two floats.
## Examples
```rescript
Int.mod(7.0, 4.0) == 3
```
*/
external mod: (float, float) => float = "?fmod_float"