forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaml_float.js
132 lines (120 loc) · 2.66 KB
/
caml_float.js
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
'use strict';
var caml_int32_float_of_bits = (function(x){
return new Float32Array(new Int32Array([x]).buffer)[0]
});
var caml_int32_bits_of_float = (function(x){
return new Int32Array(new Float32Array([x]).buffer)[0]
});
function caml_modf_float(x) {
if (!isFinite(x)) {
if (isNaN(x)) {
return [
NaN,
NaN
];
} else {
return [
1 / x,
x
];
}
}
var neg = 1 / x < 0;
var x$1 = Math.abs(x);
var i = Math.floor(x$1);
var f = x$1 - i;
if (neg) {
return [
-f,
-i
];
} else {
return [
f,
i
];
}
}
function caml_ldexp_float(x, exp) {
var x$prime = x;
var exp$prime = exp;
if (exp$prime > 1023) {
exp$prime = exp$prime - 1023;
x$prime = x$prime * Math.pow(2, 1023);
if (exp$prime > 1023) {
exp$prime = exp$prime - 1023;
x$prime = x$prime * Math.pow(2, 1023);
}
} else if (exp$prime < -1023) {
exp$prime = exp$prime + 1023;
x$prime = x$prime * Math.pow(2, -1023);
}
return x$prime * Math.pow(2, exp$prime);
}
function caml_frexp_float(x) {
if (x === 0 || !isFinite(x)) {
return [
x,
0
];
}
var neg = x < 0;
var x$prime = Math.abs(x);
var exp = Math.floor(Math.LOG2E * Math.log(x$prime)) + 1;
x$prime = x$prime * Math.pow(2, -exp);
if (x$prime < 0.5) {
x$prime = x$prime * 2;
exp = exp - 1;
}
if (neg) {
x$prime = -x$prime;
}
return [
x$prime,
exp | 0
];
}
function caml_copysign_float(x, y) {
var x$1 = Math.abs(x);
var y$1 = y === 0 ? 1 / y : y;
if (y$1 < 0) {
return -x$1;
} else {
return x$1;
}
}
function caml_expm1_float(x) {
var y = Math.exp(x);
var z = y - 1;
if (Math.abs(x) > 1) {
return z;
} else if (z === 0) {
return x;
} else {
return x * z / Math.log(y);
}
}
function caml_hypot_float(x, y) {
var x0 = Math.abs(x);
var y0 = Math.abs(y);
var a = x0 > y0 ? x0 : y0;
var b = (
x0 < y0 ? x0 : y0
) / (
a !== 0 ? a : 1
);
return a * Math.sqrt(1 + b * b);
}
function caml_log10_float(x) {
return Math.LOG10E * Math.log(x);
}
exports.caml_int32_float_of_bits = caml_int32_float_of_bits;
exports.caml_int32_bits_of_float = caml_int32_bits_of_float;
exports.caml_modf_float = caml_modf_float;
exports.caml_ldexp_float = caml_ldexp_float;
exports.caml_frexp_float = caml_frexp_float;
exports.caml_copysign_float = caml_copysign_float;
exports.caml_expm1_float = caml_expm1_float;
exports.caml_hypot_float = caml_hypot_float;
exports.caml_log10_float = caml_log10_float;
/* No side effect */