Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: src/math.js

Issue 216643002: Reland "Clean up runtime functions for Maths." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: fix Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/ia32/full-codegen-ia32.cc ('k') | src/mips/code-stubs-mips.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 // ECMA 262 - 15.8.2.1 45 // ECMA 262 - 15.8.2.1
46 function MathAbs(x) { 46 function MathAbs(x) {
47 if (%_IsSmi(x)) return x >= 0 ? x : -x; 47 if (%_IsSmi(x)) return x >= 0 ? x : -x;
48 x = TO_NUMBER_INLINE(x); 48 x = TO_NUMBER_INLINE(x);
49 if (x === 0) return 0; // To handle -0. 49 if (x === 0) return 0; // To handle -0.
50 return x > 0 ? x : -x; 50 return x > 0 ? x : -x;
51 } 51 }
52 52
53 // ECMA 262 - 15.8.2.2 53 // ECMA 262 - 15.8.2.2
54 function MathAcos(x) { 54 function MathAcos(x) {
55 return %Math_acos(TO_NUMBER_INLINE(x)); 55 return %MathAcos(TO_NUMBER_INLINE(x));
56 } 56 }
57 57
58 // ECMA 262 - 15.8.2.3 58 // ECMA 262 - 15.8.2.3
59 function MathAsin(x) { 59 function MathAsin(x) {
60 return %Math_asin(TO_NUMBER_INLINE(x)); 60 return %MathAsin(TO_NUMBER_INLINE(x));
61 } 61 }
62 62
63 // ECMA 262 - 15.8.2.4 63 // ECMA 262 - 15.8.2.4
64 function MathAtan(x) { 64 function MathAtan(x) {
65 return %Math_atan(TO_NUMBER_INLINE(x)); 65 return %MathAtan(TO_NUMBER_INLINE(x));
66 } 66 }
67 67
68 // ECMA 262 - 15.8.2.5 68 // ECMA 262 - 15.8.2.5
69 // The naming of y and x matches the spec, as does the order in which 69 // The naming of y and x matches the spec, as does the order in which
70 // ToNumber (valueOf) is called. 70 // ToNumber (valueOf) is called.
71 function MathAtan2(y, x) { 71 function MathAtan2(y, x) {
72 return %Math_atan2(TO_NUMBER_INLINE(y), TO_NUMBER_INLINE(x)); 72 return %MathAtan2(TO_NUMBER_INLINE(y), TO_NUMBER_INLINE(x));
73 } 73 }
74 74
75 // ECMA 262 - 15.8.2.6 75 // ECMA 262 - 15.8.2.6
76 function MathCeil(x) { 76 function MathCeil(x) {
77 return -MathFloor(-x); 77 return -MathFloor(-x);
78 } 78 }
79 79
80 // ECMA 262 - 15.8.2.7 80 // ECMA 262 - 15.8.2.7
81 function MathCos(x) { 81 function MathCos(x) {
82 x = MathAbs(x); // Convert to number and get rid of -0. 82 x = MathAbs(x); // Convert to number and get rid of -0.
83 return TrigonometricInterpolation(x, 1); 83 return TrigonometricInterpolation(x, 1);
84 } 84 }
85 85
86 // ECMA 262 - 15.8.2.8 86 // ECMA 262 - 15.8.2.8
87 function MathExp(x) { 87 function MathExp(x) {
88 return %Math_exp(TO_NUMBER_INLINE(x)); 88 return %MathExp(TO_NUMBER_INLINE(x));
89 } 89 }
90 90
91 // ECMA 262 - 15.8.2.9 91 // ECMA 262 - 15.8.2.9
92 function MathFloor(x) { 92 function MathFloor(x) {
93 x = TO_NUMBER_INLINE(x); 93 x = TO_NUMBER_INLINE(x);
94 // It's more common to call this with a positive number that's out 94 // It's more common to call this with a positive number that's out
95 // of range than negative numbers; check the upper bound first. 95 // of range than negative numbers; check the upper bound first.
96 if (x < 0x80000000 && x > 0) { 96 if (x < 0x80000000 && x > 0) {
97 // Numbers in the range [0, 2^31) can be floored by converting 97 // Numbers in the range [0, 2^31) can be floored by converting
98 // them to an unsigned 32-bit value using the shift operator. 98 // them to an unsigned 32-bit value using the shift operator.
99 // We avoid doing so for -0, because the result of Math.floor(-0) 99 // We avoid doing so for -0, because the result of Math.floor(-0)
100 // has to be -0, which wouldn't be the case with the shift. 100 // has to be -0, which wouldn't be the case with the shift.
101 return TO_UINT32(x); 101 return TO_UINT32(x);
102 } else { 102 } else {
103 return %Math_floor(x); 103 return %MathFloor(x);
104 } 104 }
105 } 105 }
106 106
107 // ECMA 262 - 15.8.2.10 107 // ECMA 262 - 15.8.2.10
108 function MathLog(x) { 108 function MathLog(x) {
109 return %_MathLog(TO_NUMBER_INLINE(x)); 109 return %_MathLog(TO_NUMBER_INLINE(x));
110 } 110 }
111 111
112 // ECMA 262 - 15.8.2.11 112 // ECMA 262 - 15.8.2.11
113 function MathMax(arg1, arg2) { // length == 2 113 function MathMax(arg1, arg2) { // length == 2
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 326
327 %SetInlineBuiltinFlag(MathCeil); 327 %SetInlineBuiltinFlag(MathCeil);
328 %SetInlineBuiltinFlag(MathRandom); 328 %SetInlineBuiltinFlag(MathRandom);
329 %SetInlineBuiltinFlag(MathSin); 329 %SetInlineBuiltinFlag(MathSin);
330 %SetInlineBuiltinFlag(MathCos); 330 %SetInlineBuiltinFlag(MathCos);
331 %SetInlineBuiltinFlag(MathTan); 331 %SetInlineBuiltinFlag(MathTan);
332 %SetInlineBuiltinFlag(TrigonometricInterpolation); 332 %SetInlineBuiltinFlag(TrigonometricInterpolation);
333 } 333 }
334 334
335 SetUpMath(); 335 SetUpMath();
OLDNEW
« no previous file with comments | « src/ia32/full-codegen-ia32.cc ('k') | src/mips/code-stubs-mips.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698