Revision f230a1cf deps/v8/src/math.js

View differences:

deps/v8/src/math.js
45 45
// ECMA 262 - 15.8.2.1
46 46
function MathAbs(x) {
47 47
  if (%_IsSmi(x)) return x >= 0 ? x : -x;
48
  if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
48
  x = TO_NUMBER_INLINE(x);
49 49
  if (x === 0) return 0;  // To handle -0.
50 50
  return x > 0 ? x : -x;
51 51
}
52 52

  
53 53
// ECMA 262 - 15.8.2.2
54 54
function MathAcos(x) {
55
  if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
56
  return %Math_acos(x);
55
  return %Math_acos(TO_NUMBER_INLINE(x));
57 56
}
58 57

  
59 58
// ECMA 262 - 15.8.2.3
60 59
function MathAsin(x) {
61
  if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
62
  return %Math_asin(x);
60
  return %Math_asin(TO_NUMBER_INLINE(x));
63 61
}
64 62

  
65 63
// ECMA 262 - 15.8.2.4
66 64
function MathAtan(x) {
67
  if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
68
  return %Math_atan(x);
65
  return %Math_atan(TO_NUMBER_INLINE(x));
69 66
}
70 67

  
71 68
// ECMA 262 - 15.8.2.5
72 69
// The naming of y and x matches the spec, as does the order in which
73 70
// ToNumber (valueOf) is called.
74 71
function MathAtan2(y, x) {
75
  if (!IS_NUMBER(y)) y = NonNumberToNumber(y);
76
  if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
77
  return %Math_atan2(y, x);
72
  return %Math_atan2(TO_NUMBER_INLINE(y), TO_NUMBER_INLINE(x));
78 73
}
79 74

  
80 75
// ECMA 262 - 15.8.2.6
81 76
function MathCeil(x) {
82
  if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
83
  return %Math_ceil(x);
77
  return %Math_ceil(TO_NUMBER_INLINE(x));
84 78
}
85 79

  
86 80
// ECMA 262 - 15.8.2.7
87 81
function MathCos(x) {
88
  if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
89
  return %_MathCos(x);
82
  return %_MathCos(TO_NUMBER_INLINE(x));
90 83
}
91 84

  
92 85
// ECMA 262 - 15.8.2.8
93 86
function MathExp(x) {
94
  if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
95
  return %Math_exp(x);
87
  return %Math_exp(TO_NUMBER_INLINE(x));
96 88
}
97 89

  
98 90
// ECMA 262 - 15.8.2.9
99 91
function MathFloor(x) {
100
  if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
92
  x = TO_NUMBER_INLINE(x);
101 93
  // It's more common to call this with a positive number that's out
102 94
  // of range than negative numbers; check the upper bound first.
103 95
  if (x < 0x80000000 && x > 0) {
......
113 105

  
114 106
// ECMA 262 - 15.8.2.10
115 107
function MathLog(x) {
116
  if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
117
  return %_MathLog(x);
108
  return %_MathLog(TO_NUMBER_INLINE(x));
118 109
}
119 110

  
120 111
// ECMA 262 - 15.8.2.11
121 112
function MathMax(arg1, arg2) {  // length == 2
122 113
  var length = %_ArgumentsLength();
123 114
  if (length == 2) {
124
    if (!IS_NUMBER(arg1)) arg1 = NonNumberToNumber(arg1);
125
    if (!IS_NUMBER(arg2)) arg2 = NonNumberToNumber(arg2);
115
    arg1 = TO_NUMBER_INLINE(arg1);
116
    arg2 = TO_NUMBER_INLINE(arg2);
126 117
    if (arg2 > arg1) return arg2;
127 118
    if (arg1 > arg2) return arg1;
128 119
    if (arg1 == arg2) {
......
131 122
      return (arg1 == 0 && !%_IsSmi(arg1) && 1 / arg1 < 0) ? arg2 : arg1;
132 123
    }
133 124
    // All comparisons failed, one of the arguments must be NaN.
134
    return 0/0;  // Compiler constant-folds this to NaN.
125
    return NAN;
135 126
  }
136
  var r = -1/0;  // Compiler constant-folds this to -Infinity.
127
  var r = -INFINITY;
137 128
  for (var i = 0; i < length; i++) {
138 129
    var n = %_Arguments(i);
139 130
    if (!IS_NUMBER(n)) n = NonNumberToNumber(n);
......
151 142
function MathMin(arg1, arg2) {  // length == 2
152 143
  var length = %_ArgumentsLength();
153 144
  if (length == 2) {
154
    if (!IS_NUMBER(arg1)) arg1 = NonNumberToNumber(arg1);
155
    if (!IS_NUMBER(arg2)) arg2 = NonNumberToNumber(arg2);
145
    arg1 = TO_NUMBER_INLINE(arg1);
146
    arg2 = TO_NUMBER_INLINE(arg2);
156 147
    if (arg2 > arg1) return arg1;
157 148
    if (arg1 > arg2) return arg2;
158 149
    if (arg1 == arg2) {
......
161 152
      return (arg1 == 0 && !%_IsSmi(arg1) && 1 / arg1 < 0) ? arg1 : arg2;
162 153
    }
163 154
    // All comparisons failed, one of the arguments must be NaN.
164
    return 0/0;  // Compiler constant-folds this to NaN.
155
    return NAN;
165 156
  }
166
  var r = 1/0;  // Compiler constant-folds this to Infinity.
157
  var r = INFINITY;
167 158
  for (var i = 0; i < length; i++) {
168 159
    var n = %_Arguments(i);
169 160
    if (!IS_NUMBER(n)) n = NonNumberToNumber(n);
......
179 170

  
180 171
// ECMA 262 - 15.8.2.13
181 172
function MathPow(x, y) {
182
  if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
183
  if (!IS_NUMBER(y)) y = NonNumberToNumber(y);
184
  return %_MathPow(x, y);
173
  return %_MathPow(TO_NUMBER_INLINE(x), TO_NUMBER_INLINE(y));
185 174
}
186 175

  
187 176
// ECMA 262 - 15.8.2.14
......
191 180

  
192 181
// ECMA 262 - 15.8.2.15
193 182
function MathRound(x) {
194
  if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
195
  return %RoundNumber(x);
183
  return %RoundNumber(TO_NUMBER_INLINE(x));
196 184
}
197 185

  
198 186
// ECMA 262 - 15.8.2.16
199 187
function MathSin(x) {
200
  if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
201
  return %_MathSin(x);
188
  return %_MathSin(TO_NUMBER_INLINE(x));
202 189
}
203 190

  
204 191
// ECMA 262 - 15.8.2.17
205 192
function MathSqrt(x) {
206
  if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
207
  return %_MathSqrt(x);
193
  return %_MathSqrt(TO_NUMBER_INLINE(x));
208 194
}
209 195

  
210 196
// ECMA 262 - 15.8.2.18
211 197
function MathTan(x) {
212
  if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
213
  return %_MathTan(x);
198
  return %_MathTan(TO_NUMBER_INLINE(x));
214 199
}
215 200

  
216 201
// Non-standard extension.
217 202
function MathImul(x, y) {
218
  if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
219
  if (!IS_NUMBER(y)) y = NonNumberToNumber(y);
220
  return %NumberImul(x, y);
203
  return %NumberImul(TO_NUMBER_INLINE(x), TO_NUMBER_INLINE(y));
221 204
}
222 205

  
223 206

  

Also available in: Unified diff