~yolanda.robla/ubuntu/trusty/nodejs/add_distribution

« back to all changes in this revision

Viewing changes to deps/v8/src/math.js

  • Committer: Package Import Robot
  • Author(s): Jérémy Lal
  • Date: 2013-08-14 00:16:46 UTC
  • mfrom: (7.1.40 sid)
  • Revision ID: package-import@ubuntu.com-20130814001646-bzlysfh8sd6mukbo
Tags: 0.10.15~dfsg1-4
* Update 2005 patch, adding a handful of tests that can fail on
  slow platforms.
* Add 1004 patch to fix test failures when writing NaN to buffer
  on mipsel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright 2006-2008 the V8 project authors. All rights reserved.
 
1
// Copyright 2012 the V8 project authors. All rights reserved.
2
2
// Redistribution and use in source and binary forms, with or without
3
3
// modification, are permitted provided that the following conditions are
4
4
// met:
29
29
// Keep reference to original values of some global properties.  This
30
30
// has the added benefit that the code in this file is isolated from
31
31
// changes to these properties.
32
 
const $floor = MathFloor;
33
 
const $random = MathRandom;
34
 
const $abs = MathAbs;
 
32
var $floor = MathFloor;
 
33
var $abs = MathAbs;
35
34
 
36
35
// Instance class name can only be set on functions. That is the only
37
36
// purpose for MathConstructor.
38
37
function MathConstructor() {}
39
38
%FunctionSetInstanceClassName(MathConstructor, 'Math');
40
 
const $Math = new MathConstructor();
 
39
var $Math = new MathConstructor();
41
40
$Math.__proto__ = $Object.prototype;
42
41
%SetProperty(global, "Math", $Math, DONT_ENUM);
43
42
 
119
118
// ECMA 262 - 15.8.2.11
120
119
function MathMax(arg1, arg2) {  // length == 2
121
120
  var length = %_ArgumentsLength();
 
121
  if (length == 2) {
 
122
    if (!IS_NUMBER(arg1)) arg1 = NonNumberToNumber(arg1);
 
123
    if (!IS_NUMBER(arg2)) arg2 = NonNumberToNumber(arg2);
 
124
    if (arg2 > arg1) return arg2;
 
125
    if (arg1 > arg2) return arg1;
 
126
    if (arg1 == arg2) {
 
127
      // Make sure -0 is considered less than +0.  -0 is never a Smi, +0 can be
 
128
      // a Smi or a heap number.
 
129
      return (arg1 == 0 && !%_IsSmi(arg1) && 1 / arg1 < 0) ? arg2 : arg1;
 
130
    }
 
131
    // All comparisons failed, one of the arguments must be NaN.
 
132
    return 0/0;  // Compiler constant-folds this to NaN.
 
133
  }
122
134
  if (length == 0) {
123
135
    return -1/0;  // Compiler constant-folds this to -Infinity.
124
136
  }
131
143
    if (NUMBER_IS_NAN(n)) return n;
132
144
    // Make sure +0 is considered greater than -0.  -0 is never a Smi, +0 can be
133
145
    // a Smi or heap number.
134
 
    if (n > r || (r === 0 && n === 0 && !%_IsSmi(r) && 1 / r < 0)) r = n;
 
146
    if (n > r || (r == 0 && n == 0 && !%_IsSmi(r) && 1 / r < 0)) r = n;
135
147
  }
136
148
  return r;
137
149
}
139
151
// ECMA 262 - 15.8.2.12
140
152
function MathMin(arg1, arg2) {  // length == 2
141
153
  var length = %_ArgumentsLength();
 
154
  if (length == 2) {
 
155
    if (!IS_NUMBER(arg1)) arg1 = NonNumberToNumber(arg1);
 
156
    if (!IS_NUMBER(arg2)) arg2 = NonNumberToNumber(arg2);
 
157
    if (arg2 > arg1) return arg1;
 
158
    if (arg1 > arg2) return arg2;
 
159
    if (arg1 == arg2) {
 
160
      // Make sure -0 is considered less than +0.  -0 is never a Smi, +0 can be
 
161
      // a Smi or a heap number.
 
162
      return (arg1 == 0 && !%_IsSmi(arg1) && 1 / arg1 < 0) ? arg1 : arg2;
 
163
    }
 
164
    // All comparisons failed, one of the arguments must be NaN.
 
165
    return 0/0;  // Compiler constant-folds this to NaN.
 
166
  }
142
167
  if (length == 0) {
143
168
    return 1/0;  // Compiler constant-folds this to Infinity.
144
169
  }
149
174
    var n = %_Arguments(i);
150
175
    if (!IS_NUMBER(n)) n = NonNumberToNumber(n);
151
176
    if (NUMBER_IS_NAN(n)) return n;
152
 
    // Make sure -0 is considered less than +0.  -0 is never a Smi, +0 can b a
 
177
    // Make sure -0 is considered less than +0.  -0 is never a Smi, +0 can be a
153
178
    // Smi or a heap number.
154
 
    if (n < r || (r === 0 && n === 0 && !%_IsSmi(n) && 1 / n < 0)) r = n;
 
179
    if (n < r || (r == 0 && n == 0 && !%_IsSmi(n) && 1 / n < 0)) r = n;
155
180
  }
156
181
  return r;
157
182
}
189
214
// ECMA 262 - 15.8.2.18
190
215
function MathTan(x) {
191
216
  if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
192
 
  return %Math_tan(x);
 
217
  return %_MathTan(x);
193
218
}
194
219
 
195
220
 
239
264
 
240
265
  // Set up non-enumerable functions of the Math object and
241
266
  // set their names.
242
 
  InstallFunctionsOnHiddenPrototype($Math, DONT_ENUM, $Array(
 
267
  InstallFunctions($Math, DONT_ENUM, $Array(
243
268
    "random", MathRandom,
244
269
    "abs", MathAbs,
245
270
    "acos", MathAcos,