forked from rescript-lang/rescript-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCore__Float.res
More file actions
42 lines (33 loc) · 1.63 KB
/
Core__Float.res
File metadata and controls
42 lines (33 loc) · 1.63 KB
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
module Constants = {
@val external nan: float = "NaN"
@val external epsilon: float = "Number.EPSILON"
@val external positiveInfinity: float = "Number.POSITIVE_INFINITY"
@val external negativeInfinity: float = "Number.NEGATIVE_INFINITY"
@val external minValue: float = "Number.MIN_VALUE"
@val external maxValue: float = "Number.MAX_VALUE"
}
@val external isNaN: float => bool = "isNaN"
@val external isFinite: float => bool = "isFinite"
@val external parseFloat: 'a => float = "parseFloat"
// parseInt's return type is a float because it can be NaN
@val external parseInt: 'a => float = "parseInt"
@val external parseIntWithRadix: ('a, ~radix: int) => float = "parseInt"
@send external toExponential: float => string = "toExponential"
@send external toExponentialWithPrecision: (float, ~digits: int) => string = "toExponential"
@send external toFixed: float => string = "toFixed"
@send external toFixedWithPrecision: (float, ~digits: int) => string = "toFixed"
@send external toPrecision: float => string = "toPrecision"
@send external toPrecisionWithPrecision: (float, ~digits: int) => string = "toPrecision"
@send external toString: float => string = "toString"
@send external toStringWithRadix: (float, ~radix: int) => string = "toString"
@send external toLocaleString: float => string = "toLocaleString"
let fromString: string => option<float> = %raw(`function (str) {
if (!str || !str.trim()) {
return undefined;
}
let num = +str;
return isNaN(num) ? undefined : num;
}`)
external toInt: float => int = "%intoffloat"
external fromInt: int => float = "%identity"
@unboxed @noalloc external mod: (float, float) => float = "?fmod_float"