Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 12 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /css/css-values/hypot-pow-sqrt-computed.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<link rel="author" title="Apple Inc">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../support/numeric-testcommon.js"></script>
<div>
<div></div>
<div></div>
<div></div>
<div id="target"></div>
</div>
<script>
// Identity tests
test_math_used('pow(1,1)', '1', {type:'integer'});
test_math_used('sqrt(1)', '1', {type:'integer'});
test_math_used('hypot(1)', '1', {type:'integer'});
// Nestings
test_math_used('sqrt(pow(1,1))', '1', {type:'integer'});
test_math_used('hypot(pow(1, sqrt(1)))', '1', {type:'integer'});
test_math_used('calc(hypot(pow((1 + sqrt(1)) / 2, sqrt(1))))', '1', {type:'integer'});
// General calculations
test_math_used('calc(100px * pow(2, pow(2, 2)))','1600px');
test_math_used('calc(1px * pow(2, 3))', '8px')
test_math_used('calc(100px * sqrt(100))', '1000px');
test_math_used('calc(1px * pow(2, sqrt(100))', '1024px');
test_math_used('hypot(3px, 4px)', '5px');
test_math_used('hypot(3e+9px, 4e+9px)', '5e+9px');
test_math_used('calc(100px * hypot(3, 4))', '500px');
test_math_used('hypot(-5px)', '5px');
test_math_used('calc(1px * hypot(-5))', '5px');
test_math_used('calc(1px * hypot(10000))','10000px');
test_math_used('calc(2px * sqrt(100000000))','20000px');
test_math_used('calc(3px * pow(20, 4))', '480000px');
test_math_used('calc(-2 * hypot(3px, 4px))', '-10px');
test_math_used('hypot(0% + 3px, 0% + 4px)', '5px');
test_math_used('hypot(0% + 772.333px)', 'calc(0% + 772.333px)');
test_math_used('hypot(0% + 772.35px)', 'calc(0% + 772.35px)');
test_math_used('hypot(0% + 600px, 0% + 800px)', '1000px');
// Test unresolved at parse time
test_math_used('sqrt(sibling-index())', '2', {type: 'integer'});
test_math_used('calc(1px * sqrt(sibling-index()))', '2px');
test_math_used('sqrt(pow(sibling-index(), 2))', '4', {type: 'integer'});
test_math_used('hypot(3, sibling-index())', '5', {type: 'integer'});
test_math_used('sqrt(4 * sign(1em - 1px))', '2', {type: 'integer'});
test_math_used('calc(1px * sqrt(4 * sign(1em - 1px)))', '2px');
test_math_used('sqrt(pow(4 * sign(1em - 1px), 2))', '4', {type: 'integer'});
test_math_used('hypot(3, 4 * sign(1em - 1px))', '5', {type: 'integer'});
// Test unresolved at computed-value time.
test_math_computed('calc(pow(tan(atan2(round(up,1px,100%),round(up,1px,100%))),2)*1px)',
'calc(pow(tan(atan2(round(up,1px,100%),round(up,1px,100%))),2)*1px)', {type:'length'});
// Special values: pow()
// If A is negative and finite, and B is finite, B must be an integer.
test_nan('pow(-2, 0.5)');
test_nan('pow(-8, 1 / 3)');
// Table 1: A is -infinity / 0- / 0+ / +infinity.
test_minus_zero('pow(-infinity, -3)');
test_plus_zero('pow(-infinity, -2)');
test_minus_zero('pow(-infinity, -1)');
test_math_used('pow(-infinity, 0)', '1', {type: 'number'});
test_minus_infinity('pow(-infinity, 1)');
test_plus_infinity('pow(-infinity, 2)');
test_minus_infinity('pow(-infinity, 3)');
test_minus_infinity('pow(-0, -3)');
test_plus_infinity('pow(-0, -2)');
test_minus_infinity('pow(-0, -1)');
test_math_used('pow(-0, 0)', '1', {type: 'number'});
test_minus_zero('pow(-0, 1)');
test_plus_zero('pow(-0, 2)');
test_minus_zero('pow(-0, 3)');
test_plus_infinity('pow(0, -3)');
test_plus_infinity('pow(0, -1)');
test_math_used('pow(0, 0)', '1', {type: 'number'});
test_plus_zero('pow(0, 1)');
test_plus_zero('pow(0, 2)');
test_plus_zero('pow(infinity, -3)');
test_plus_zero('pow(infinity, -1)');
test_math_used('pow(infinity, 0)', '1', {type: 'number'});
test_plus_infinity('pow(infinity, 1)');
test_plus_infinity('pow(infinity, 2)');
// Table 2: B is +/-infinity, A relative to -1 / 0 / 1.
test_plus_infinity('pow(-2, infinity)');
test_nan('pow(-1, infinity)');
test_plus_zero('pow(-0.5, infinity)');
test_plus_zero('pow(0.5, infinity)');
test_nan('pow(1, infinity)');
test_plus_infinity('pow(2, infinity)');
test_plus_zero('pow(-2, -infinity)');
test_nan('pow(-1, -infinity)');
test_plus_infinity('pow(-0.5, -infinity)');
test_plus_infinity('pow(0.5, -infinity)');
test_nan('pow(1, -infinity)');
test_plus_zero('pow(2, -infinity)');
// NaN is infectious, including pow(NaN, 0) and pow(1, NaN)
// where JS `Math.pow` would return 1.
test_nan('pow(NaN, 0)');
test_nan('pow(1, NaN)');
test_nan('pow(NaN, NaN)');
// sqrt()
test_minus_zero('sqrt(-0)');
test_plus_infinity('sqrt(infinity)');
test_nan('sqrt(-1)');
test_nan('sqrt(NaN)');
test_nan('sqrt(-infinity)');
// hypot()
test_math_used('hypot(3, 4)', '5', {type: 'number'});
test_plus_infinity('hypot(infinity, 5)');
test_plus_infinity('hypot(5, infinity)');
test_plus_infinity('hypot(-infinity, 5)');
// NaN is infectious, so hypot(infinity, NaN) is NaN
// even though JS `Math.hypot(Infinity, NaN)` returns Infinity.
test_nan('hypot(NaN, 5)');
test_nan('hypot(5, NaN)');
test_nan('hypot(infinity, NaN)');
test_nan('hypot(NaN, infinity)');
// Type checking hypot
test_math_used('hypot(1px)', '1px');
test_math_used('hypot(1cm)', '1cm');
test_math_used('hypot(1mm)', '1mm');
test_math_used('hypot(1Q)', '1Q');
test_math_used('hypot(1in)', '1in');
test_math_used('hypot(1pc)', '1pc');
test_math_used('hypot(1pt)', '1pt');
test_math_used('hypot(1em)', '1em');
test_math_used('hypot(1ex)', '1ex');
test_math_used('hypot(1ch)', '1ch');
test_math_used('hypot(1rem)', '1rem');
test_math_used('hypot(1vh)', '1vh');
test_math_used('hypot(1vw)', '1vw');
test_math_used('hypot(1vmin)', '1vmin');
test_math_used('hypot(1vmax)', '1vmax');
test_math_used('hypot(1s)', '1s', {type:'time'});
test_math_used('hypot(1ms)', '1ms', {type:'time'});
test_math_used('hypot(1deg)', '1deg', {type:'angle', approx:0.001});
test_math_used('hypot(1grad)', '1grad', {type:'angle', approx:0.001});
test_math_used('hypot(1rad)', '1rad', {type:'angle', approx:0.001});
test_math_used('hypot(1turn)', '1turn', {type:'angle', approx:0.001});
</script>