Source code

Revision control

Other Tools

1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2
* vim: set ts=8 sts=2 et sw=2 tw=80:
3
* This Source Code Form is subject to the terms of the Mozilla Public
4
* License, v. 2.0. If a copy of the MPL was not distributed with this
5
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef jsmath_h
8
#define jsmath_h
9
10
#include "mozilla/MemoryReporting.h"
11
12
#include <stdint.h>
13
14
#include "NamespaceImports.h"
15
16
namespace js {
17
18
class GlobalObject;
19
20
typedef double (*UnaryFunType)(double);
21
22
/*
23
* JS math functions.
24
*/
25
26
extern const JSClass MathClass;
27
28
extern JSObject* InitMathClass(JSContext* cx, Handle<GlobalObject*> global);
29
30
extern uint64_t GenerateRandomSeed();
31
32
// Fill |seed[0]| and |seed[1]| with random bits, suitable for
33
// seeding a XorShift128+ random number generator.
34
extern void GenerateXorShift128PlusSeed(mozilla::Array<uint64_t, 2>& seed);
35
36
extern double math_random_impl(JSContext* cx);
37
38
extern bool math_random(JSContext* cx, unsigned argc, js::Value* vp);
39
40
extern bool math_abs_handle(JSContext* cx, js::HandleValue v,
41
js::MutableHandleValue r);
42
43
extern bool math_abs(JSContext* cx, unsigned argc, js::Value* vp);
44
45
extern double math_max_impl(double x, double y);
46
47
extern bool math_max(JSContext* cx, unsigned argc, js::Value* vp);
48
49
extern double math_min_impl(double x, double y);
50
51
extern bool math_min(JSContext* cx, unsigned argc, js::Value* vp);
52
53
extern double math_sqrt_impl(double x);
54
55
extern bool math_sqrt_handle(JSContext* cx, js::HandleValue number,
56
js::MutableHandleValue result);
57
58
extern bool math_sqrt(JSContext* cx, unsigned argc, js::Value* vp);
59
60
extern bool math_pow(JSContext* cx, unsigned argc, js::Value* vp);
61
62
extern bool minmax_impl(JSContext* cx, bool max, js::HandleValue a,
63
js::HandleValue b, js::MutableHandleValue res);
64
65
extern bool math_imul_handle(JSContext* cx, HandleValue lhs, HandleValue rhs,
66
MutableHandleValue res);
67
68
extern bool math_imul(JSContext* cx, unsigned argc, js::Value* vp);
69
70
extern bool RoundFloat32(JSContext* cx, HandleValue v, float* out);
71
72
extern bool RoundFloat32(JSContext* cx, HandleValue arg,
73
MutableHandleValue res);
74
75
extern bool math_fround(JSContext* cx, unsigned argc, js::Value* vp);
76
77
extern bool math_log(JSContext* cx, unsigned argc, js::Value* vp);
78
79
extern double math_log_impl(double x);
80
81
extern bool math_log_handle(JSContext* cx, HandleValue val,
82
MutableHandleValue res);
83
84
extern bool math_sin(JSContext* cx, unsigned argc, js::Value* vp);
85
86
extern double math_sin_impl(double x);
87
88
extern bool math_sin_handle(JSContext* cx, HandleValue val,
89
MutableHandleValue res);
90
91
extern bool math_cos(JSContext* cx, unsigned argc, js::Value* vp);
92
93
extern double math_cos_impl(double x);
94
95
extern bool math_exp(JSContext* cx, unsigned argc, js::Value* vp);
96
97
extern double math_exp_impl(double x);
98
99
extern bool math_tan(JSContext* cx, unsigned argc, js::Value* vp);
100
101
extern double math_tan_impl(double x);
102
103
extern bool math_log10(JSContext* cx, unsigned argc, js::Value* vp);
104
105
extern bool math_log2(JSContext* cx, unsigned argc, js::Value* vp);
106
107
extern bool math_log1p(JSContext* cx, unsigned argc, js::Value* vp);
108
109
extern bool math_expm1(JSContext* cx, unsigned argc, js::Value* vp);
110
111
extern bool math_cosh(JSContext* cx, unsigned argc, js::Value* vp);
112
113
extern bool math_sinh(JSContext* cx, unsigned argc, js::Value* vp);
114
115
extern bool math_tanh(JSContext* cx, unsigned argc, js::Value* vp);
116
117
extern bool math_acosh(JSContext* cx, unsigned argc, js::Value* vp);
118
119
extern bool math_asinh(JSContext* cx, unsigned argc, js::Value* vp);
120
121
extern bool math_atanh(JSContext* cx, unsigned argc, js::Value* vp);
122
123
extern double ecmaHypot(double x, double y);
124
125
extern double hypot3(double x, double y, double z);
126
127
extern double hypot4(double x, double y, double z, double w);
128
129
extern bool math_hypot(JSContext* cx, unsigned argc, Value* vp);
130
131
extern bool math_hypot_handle(JSContext* cx, HandleValueArray args,
132
MutableHandleValue res);
133
134
extern bool math_trunc(JSContext* cx, unsigned argc, Value* vp);
135
136
extern bool math_sign(JSContext* cx, unsigned argc, Value* vp);
137
138
extern bool math_cbrt(JSContext* cx, unsigned argc, Value* vp);
139
140
extern bool math_asin(JSContext* cx, unsigned argc, Value* vp);
141
142
extern bool math_acos(JSContext* cx, unsigned argc, Value* vp);
143
144
extern bool math_atan(JSContext* cx, unsigned argc, Value* vp);
145
146
extern bool math_atan2_handle(JSContext* cx, HandleValue y, HandleValue x,
147
MutableHandleValue res);
148
149
extern bool math_atan2(JSContext* cx, unsigned argc, Value* vp);
150
151
extern double ecmaAtan2(double x, double y);
152
153
extern double math_atan_impl(double x);
154
155
extern bool math_atan(JSContext* cx, unsigned argc, js::Value* vp);
156
157
extern double math_asin_impl(double x);
158
159
extern bool math_asin(JSContext* cx, unsigned argc, js::Value* vp);
160
161
extern double math_acos_impl(double x);
162
163
extern bool math_acos(JSContext* cx, unsigned argc, js::Value* vp);
164
165
extern bool math_ceil_handle(JSContext* cx, HandleValue value,
166
MutableHandleValue res);
167
168
extern bool math_ceil(JSContext* cx, unsigned argc, Value* vp);
169
170
extern double math_ceil_impl(double x);
171
172
extern bool math_clz32(JSContext* cx, unsigned argc, Value* vp);
173
174
extern bool math_floor_handle(JSContext* cx, HandleValue v,
175
MutableHandleValue r);
176
177
extern bool math_floor(JSContext* cx, unsigned argc, Value* vp);
178
179
extern double math_floor_impl(double x);
180
181
template <typename T>
182
extern T GetBiggestNumberLessThan(T x);
183
184
extern bool math_round_handle(JSContext* cx, HandleValue arg,
185
MutableHandleValue res);
186
187
extern bool math_round(JSContext* cx, unsigned argc, Value* vp);
188
189
extern double math_round_impl(double x);
190
191
extern float math_roundf_impl(float x);
192
193
extern double powi(double x, int32_t y);
194
195
extern double ecmaPow(double x, double y);
196
197
extern double math_log10_impl(double x);
198
199
extern double math_log2_impl(double x);
200
201
extern double math_log1p_impl(double x);
202
203
extern double math_expm1_impl(double x);
204
205
extern double math_cosh_impl(double x);
206
207
extern double math_sinh_impl(double x);
208
209
extern double math_tanh_impl(double x);
210
211
extern double math_acosh_impl(double x);
212
213
extern double math_asinh_impl(double x);
214
215
extern double math_atanh_impl(double x);
216
217
extern double math_trunc_impl(double x);
218
219
extern float math_truncf_impl(float x);
220
221
extern bool math_trunc_handle(JSContext* cx, HandleValue v,
222
MutableHandleValue r);
223
224
extern double math_sign_impl(double x);
225
226
extern bool math_sign_handle(JSContext* cx, HandleValue v,
227
MutableHandleValue r);
228
229
extern double math_cbrt_impl(double x);
230
231
} /* namespace js */
232
233
#endif /* jsmath_h */