1 //@ run("no-architecture-specific-optimizations", "--enableArchitectureSpecificOptimizations=false", *NO_CJIT_OPTIONS)
2 //@ run("no-architecture-specific-optimizations-ftl", "--enableArchitectureSpecificOptimizations=false", *FTL_OPTIONS)
4 // Basic cases of Math.sqrt().
5 function sqrtOnInteger(radicand
) {
6 return Math
.sqrt(radicand
);
8 noInline(sqrtOnInteger
);
10 function testSquareRoot16() {
11 for (var i
= 0; i
< 10000; ++i
) {
12 var result
= sqrtOnInteger(16);
14 throw "sqrtOnInteger(16) = " + result
+ ", expected 4";
19 var sqrtOnIntegerNegativeNumber
= sqrtOnDouble(-4);
20 if (!isNaN(sqrtOnIntegerNegativeNumber
))
21 throw "sqrtOnDouble(-4) = " + sqrtOnIntegerNegativeNumber
+ ", expected NaN";
23 var sqrtOnIntegerFallback
= sqrtOnInteger(Math
.PI
);
24 if (sqrtOnIntegerFallback
!= 1.7724538509055159)
25 throw "sqrtOnInteger(Math.PI) = " + sqrtOnIntegerFallback
+ ", expected 1.7724538509055159";
28 function sqrtOnDouble(radicand
) {
29 return Math
.sqrt(radicand
);
31 noInline(sqrtOnDouble
);
33 function testSquareRootDouble() {
34 for (var i
= 0; i
< 10000; ++i
) {
35 var result
= sqrtOnInteger(Math
.LN2
);
36 if (result
!== 0.8325546111576977)
37 throw "sqrtOnInteger(Math.LN2) = " + result
+ ", expected 0.8325546111576977";
40 testSquareRootDouble();
42 var sqrtOnDoubleNegativeNumber
= sqrtOnDouble(-Math
.PI
);
43 if (!isNaN(sqrtOnDoubleNegativeNumber
))
44 throw "sqrtOnDouble(-Math.PI) = " + sqrtOnDoubleNegativeNumber
+ ", expected NaN";
46 var sqrtOnDoubleFallback
= sqrtOnDouble(4);
47 if (sqrtOnDoubleFallback
!== 2)
48 throw "sqrtOnDouble(4) = " + sqrtOnDoubleFallback
+ ", expected 2";