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