| 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 <stdint.h> |
| 11 |
|
| 12 |
#include "NamespaceImports.h" |
| 13 |
|
| 14 |
namespace js { |
| 15 |
|
| 16 |
using UnaryMathFunctionType = double (*)(double); |
| 17 |
|
| 18 |
// Used for inlining calls to double => double Math functions from JIT code. |
| 19 |
// Note that this list does not include all unary Math functions: abs and sqrt |
| 20 |
// for example are missing because the JITs optimize them without a C++ call. |
| 21 |
enum class UnaryMathFunction : uint8_t { |
| 22 |
SinNative, |
| 23 |
SinFdlibm, |
| 24 |
CosNative, |
| 25 |
CosFdlibm, |
| 26 |
TanNative, |
| 27 |
TanFdlibm, |
| 28 |
Log, |
| 29 |
Exp, |
| 30 |
ACos, |
| 31 |
ASin, |
| 32 |
ATan, |
| 33 |
Log10, |
| 34 |
Log2, |
| 35 |
Log1P, |
| 36 |
ExpM1, |
| 37 |
CosH, |
| 38 |
SinH, |
| 39 |
TanH, |
| 40 |
ACosH, |
| 41 |
ASinH, |
| 42 |
ATanH, |
| 43 |
Trunc, |
| 44 |
Cbrt, |
| 45 |
Floor, |
| 46 |
Ceil, |
| 47 |
Round, |
| 48 |
}; |
| 49 |
|
| 50 |
extern UnaryMathFunctionType GetUnaryMathFunctionPtr(UnaryMathFunction fun); |
| 51 |
extern const char* GetUnaryMathFunctionName(UnaryMathFunction fun, |
| 52 |
bool enumName = false); |
| 53 |
|
| 54 |
/* |
| 55 |
* JS math functions. |
| 56 |
*/ |
| 57 |
|
| 58 |
extern const JSClass MathClass; |
| 59 |
|
| 60 |
extern uint64_t GenerateRandomSeed(); |
| 61 |
|
| 62 |
// Fill |seed[0]| and |seed[1]| with random bits, suitable for |
| 63 |
// seeding a XorShift128+ random number generator. |
| 64 |
extern void GenerateXorShift128PlusSeed(mozilla::Array<uint64_t, 2>& seed); |
| 65 |
|
| 66 |
extern double math_random_impl(JSContext* cx); |
| 67 |
|
| 68 |
extern double math_abs_impl(double x); |
| 69 |
|
| 70 |
extern bool math_abs(JSContext* cx, unsigned argc, js::Value* vp); |
| 71 |
|
| 72 |
extern double math_max_impl(double x, double y); |
| 73 |
|
| 74 |
extern bool math_max(JSContext* cx, unsigned argc, js::Value* vp); |
| 75 |
|
| 76 |
extern double math_min_impl(double x, double y); |
| 77 |
|
| 78 |
extern bool math_min(JSContext* cx, unsigned argc, js::Value* vp); |
| 79 |
|
| 80 |
extern double math_sqrt_impl(double x); |
| 81 |
|
| 82 |
extern bool math_imul_handle(JSContext* cx, HandleValue lhs, HandleValue rhs, |
| 83 |
MutableHandleValue res); |
| 84 |
|
| 85 |
extern bool RoundFloat32(JSContext* cx, HandleValue v, float* out); |
| 86 |
|
| 87 |
extern bool RoundFloat32(JSContext* cx, HandleValue arg, |
| 88 |
MutableHandleValue res); |
| 89 |
|
| 90 |
extern double RoundFloat32(double d); |
| 91 |
|
| 92 |
extern double RoundFloat16(double d); |
| 93 |
|
| 94 |
extern double math_log_impl(double x); |
| 95 |
|
| 96 |
extern bool math_use_fdlibm_for_sin_cos_tan(); |
| 97 |
|
| 98 |
extern double math_sin_fdlibm_impl(double x); |
| 99 |
extern double math_sin_native_impl(double x); |
| 100 |
|
| 101 |
extern double math_cos_fdlibm_impl(double x); |
| 102 |
extern double math_cos_native_impl(double x); |
| 103 |
|
| 104 |
extern double math_exp_impl(double x); |
| 105 |
|
| 106 |
extern double math_tan_fdlibm_impl(double x); |
| 107 |
extern double math_tan_native_impl(double x); |
| 108 |
|
| 109 |
extern double ecmaHypot(double x, double y); |
| 110 |
|
| 111 |
extern double hypot3(double x, double y, double z); |
| 112 |
|
| 113 |
extern double hypot4(double x, double y, double z, double w); |
| 114 |
|
| 115 |
extern bool math_hypot_handle(JSContext* cx, HandleValueArray args, |
| 116 |
MutableHandleValue res); |
| 117 |
|
| 118 |
extern bool math_trunc(JSContext* cx, unsigned argc, Value* vp); |
| 119 |
|
| 120 |
extern double ecmaAtan2(double x, double y); |
| 121 |
|
| 122 |
extern double math_atan_impl(double x); |
| 123 |
|
| 124 |
extern double math_asin_impl(double x); |
| 125 |
|
| 126 |
extern double math_acos_impl(double x); |
| 127 |
|
| 128 |
extern double math_ceil_impl(double x); |
| 129 |
|
| 130 |
extern bool math_floor(JSContext* cx, unsigned argc, Value* vp); |
| 131 |
|
| 132 |
extern double math_floor_impl(double x); |
| 133 |
|
| 134 |
template <typename T> |
| 135 |
extern T GetBiggestNumberLessThan(T x); |
| 136 |
|
| 137 |
extern double math_round_impl(double x); |
| 138 |
|
| 139 |
extern float math_roundf_impl(float x); |
| 140 |
|
| 141 |
extern double powi(double x, int32_t y); |
| 142 |
|
| 143 |
extern double ecmaPow(double x, double y); |
| 144 |
|
| 145 |
extern double math_log10_impl(double x); |
| 146 |
|
| 147 |
extern double math_log2_impl(double x); |
| 148 |
|
| 149 |
extern double math_log1p_impl(double x); |
| 150 |
|
| 151 |
extern double math_expm1_impl(double x); |
| 152 |
|
| 153 |
extern double math_cosh_impl(double x); |
| 154 |
|
| 155 |
extern double math_sinh_impl(double x); |
| 156 |
|
| 157 |
extern double math_tanh_impl(double x); |
| 158 |
|
| 159 |
extern double math_acosh_impl(double x); |
| 160 |
|
| 161 |
extern double math_asinh_impl(double x); |
| 162 |
|
| 163 |
extern double math_atanh_impl(double x); |
| 164 |
|
| 165 |
extern double math_trunc_impl(double x); |
| 166 |
|
| 167 |
extern float math_truncf_impl(float x); |
| 168 |
|
| 169 |
extern bool math_sign(JSContext* cx, unsigned argc, Value* vp); |
| 170 |
|
| 171 |
extern double math_sign_impl(double x); |
| 172 |
|
| 173 |
extern double math_cbrt_impl(double x); |
| 174 |
|
| 175 |
} /* namespace js */ |
| 176 |
|
| 177 |
#endif /* jsmath_h */ |