1--TEST-- 2Various pow() tests 3--FILE-- 4<?php 5 6define('LONG_MAX', is_int(5000000000)? 9223372036854775807 : 0x7FFFFFFF); 7define('LONG_MIN', -LONG_MAX - 1); 8printf("%d,%d,%d,%d\n",is_int(LONG_MIN ),is_int(LONG_MAX ), 9 is_int(LONG_MIN-1),is_int(LONG_MAX+1)); 10 11function epsilon_equal($left, $right): bool { 12 return abs(($left-$right) / $left) < 1e-12; 13} 14 15var_dump(0.25 === pow(-2,-2)); 16var_dump(-0.5 === pow(-2,-1)); 17var_dump(1 === pow(-2, 0)); 18var_dump(-2 === pow(-2, 1)); 19var_dump(4 === pow(-2, 2)); 20var_dump(1.0 === pow(-1,-2)); 21var_dump(-1.0 === pow(-1,-1)); 22var_dump(1 === pow(-1, 0)); 23var_dump(-1 === pow(-1, 1)); 24var_dump(1 === pow(-1, 2)); 25var_dump(TRUE === is_infinite(pow(0,-2))); 26var_dump(TRUE === is_infinite(pow(0,-1))); 27var_dump(1 === pow( 0, 0)); 28var_dump(0 === pow( 0, 1)); 29var_dump(0 === pow( 0, 2)); 30var_dump(1.0 === pow( 1,-2)); 31var_dump(1.0 === pow( 1,-1)); 32var_dump(1 === pow( 1, 0)); 33var_dump(1 === pow( 1, 1)); 34var_dump(1 === pow( 1, 2)); 35var_dump(0.25 === pow( 2,-2)); 36var_dump(0.5 === pow( 2,-1)); 37var_dump(1 === pow( 2, 0)); 38var_dump(2 === pow( 2, 1)); 39var_dump(4 === pow( 2, 2)); 40var_dump(0.25 === pow(-2,-2.0)); 41var_dump(-0.5 === pow(-2,-1.0)); 42var_dump(1.0 === pow(-2, 0.0)); 43var_dump(-2.0 === pow(-2, 1.0)); 44var_dump(4.0 === pow(-2, 2.0)); 45var_dump(1.0 === pow(-1,-2.0)); 46var_dump(-1.0 === pow(-1,-1.0)); 47var_dump(1.0 === pow(-1, 0.0)); 48var_dump(-1.0 === pow(-1, 1.0)); 49var_dump(1.0 === pow(-1, 2.0)); 50var_dump(TRUE === is_infinite(pow(0,-2.0))); 51var_dump(TRUE === is_infinite(pow(0,-1.0))); 52var_dump(1.0 === pow( 0, 0.0)); 53var_dump(0.0 === pow( 0, 1.0)); 54var_dump(0.0 === pow( 0, 2.0)); 55var_dump(1.0 === pow( 1,-2.0)); 56var_dump(1.0 === pow( 1,-1.0)); 57var_dump(1.0 === pow( 1, 0.0)); 58var_dump(1.0 === pow( 1, 1.0)); 59var_dump(1.0 === pow( 1, 2.0)); 60var_dump(0.25 === pow( 2,-2.0)); 61var_dump(0.5 === pow( 2,-1.0)); 62var_dump(1.0 === pow( 2, 0.0)); 63var_dump(2.0 === pow( 2, 1.0)); 64var_dump(4.0 === pow( 2, 2.0)); 65var_dump(2147483648 === pow(2,31)); 66var_dump(epsilon_equal( -2147483648, pow(-2,31) )); 67var_dump(1000000000 === pow(10,9)); 68var_dump(100000000 === pow(-10,8)); 69var_dump(1 === pow(-1,1443279822)); 70var_dump(-1 === pow(-1,1443279821)); 71var_dump(epsilon_equal( sqrt(2), pow(2,1/2) )); 72var_dump(0.25 === pow(-2.0,-2.0)); 73var_dump(-0.5 === pow(-2.0,-1.0)); 74var_dump(1.0 === pow(-2.0, 0.0)); 75var_dump(-2.0 === pow(-2.0, 1.0)); 76var_dump(4.0 === pow(-2.0, 2.0)); 77var_dump(1.0 === pow(-1.0,-2.0)); 78var_dump(-1.0 === pow(-1.0,-1.0)); 79var_dump(1.0 === pow(-1.0, 0.0)); 80var_dump(-1.0 === pow(-1.0, 1.0)); 81var_dump(1.0 === pow(-1.0, 2.0)); 82var_dump(TRUE === is_infinite(pow(0.0,-2.0))); 83var_dump(TRUE === is_infinite(pow(0.0,-1.0))); 84var_dump(1.0 === pow( 0.0, 0.0)); 85var_dump(0.0 === pow( 0.0, 1.0)); 86var_dump(0.0 === pow( 0.0, 2.0)); 87var_dump(1.0 === pow( 1.0,-2.0)); 88var_dump(1.0 === pow( 1.0,-1.0)); 89var_dump(1.0 === pow( 1.0, 0.0)); 90var_dump(1.0 === pow( 1.0, 1.0)); 91var_dump(1.0 === pow( 1.0, 2.0)); 92var_dump(0.25 === pow( 2.0,-2.0)); 93var_dump(0.5 === pow( 2.0,-1.0)); 94var_dump(1.0 === pow( 2.0, 0.0)); 95var_dump(2.0 === pow( 2.0, 1.0)); 96var_dump(4.0 === pow( 2.0, 2.0)); 97var_dump(0.25 === pow(-2.0,-2)); 98var_dump(-0.5 === pow(-2.0,-1)); 99var_dump(1.0 === pow(-2.0, 0)); 100var_dump(-2.0 === pow(-2.0, 1)); 101var_dump(4.0 === pow(-2.0, 2)); 102var_dump(1.0 === pow(-1.0,-2)); 103var_dump(-1.0 === pow(-1.0,-1)); 104var_dump(1.0 === pow(-1.0, 0)); 105var_dump(-1.0 === pow(-1.0, 1)); 106var_dump(1.0 === pow(-1.0, 2)); 107var_dump(TRUE === is_infinite(pow( 0.0,-2))); 108var_dump(TRUE === is_infinite(pow( 0.0,-1))); 109var_dump(1.0 === pow( 0.0, 0)); 110var_dump(0.0 === pow( 0.0, 1)); 111var_dump(0.0 === pow( 0.0, 2)); 112var_dump(1.0 === pow( 1.0,-2)); 113var_dump(1.0 === pow( 1.0,-1)); 114var_dump(1.0 === pow( 1.0, 0)); 115var_dump(1.0 === pow( 1.0, 1)); 116var_dump(1.0 === pow( 1.0, 2)); 117var_dump(0.25 === pow( 2.0,-2)); 118var_dump(0.5 === pow( 2.0,-1)); 119var_dump(1.0 === pow( 2.0, 0)); 120var_dump(2.0 === pow( 2.0, 1)); 121var_dump(4.0 === pow( 2.0, 2)); 122var_dump(2.0 === pow( 4, 0.5)); 123var_dump(2.0 === pow( 4.0, 0.5)); 124var_dump(3.0 === pow( 27, 1/3)); 125var_dump(3.0 === pow(27.0, 1/3)); 126var_dump(0.5 === pow( 4, -0.5)); 127var_dump(0.5 === pow( 4.0, -0.5)); 128var_dump(LONG_MAX-1 === pow(LONG_MAX-1,1)); 129var_dump(LONG_MIN+1 === pow(LONG_MIN+1,1)); 130var_dump(epsilon_equal( (LONG_MAX-1)*(LONG_MAX-1) , pow(LONG_MAX-1,2) )); 131var_dump(epsilon_equal( (LONG_MIN+1)*(LONG_MIN+1) , pow(LONG_MIN+1,2) )); 132var_dump((float)(LONG_MAX-1) === pow(LONG_MAX-1,1.0)); 133var_dump((float)(LONG_MIN+1) === pow(LONG_MIN+1,1.0)); 134var_dump(epsilon_equal( (LONG_MAX-1)*(LONG_MAX-1) , pow(LONG_MAX-1,2.0) )); 135var_dump(epsilon_equal( (LONG_MIN+1)*(LONG_MIN+1) , pow(LONG_MIN+1,2.0) )); 136var_dump(LONG_MAX === pow(LONG_MAX,1)); 137var_dump(LONG_MIN === pow(LONG_MIN,1)); 138var_dump(epsilon_equal( LONG_MAX*LONG_MAX , pow(LONG_MAX,2) )); 139var_dump(epsilon_equal( LONG_MIN*LONG_MIN , pow(LONG_MIN,2) )); 140var_dump((float)LONG_MAX === pow(LONG_MAX,1.0)); 141var_dump((float)LONG_MIN === pow(LONG_MIN,1.0)); 142var_dump(epsilon_equal( LONG_MAX*LONG_MAX , pow(LONG_MAX,2.0) )); 143var_dump(epsilon_equal( LONG_MIN*LONG_MIN , pow(LONG_MIN,2.0) )); 144 145?> 146--EXPECTF-- 1471,1,0,0 148bool(true) 149bool(true) 150bool(true) 151bool(true) 152bool(true) 153bool(true) 154bool(true) 155bool(true) 156bool(true) 157bool(true) 158 159Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d 160bool(true) 161 162Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d 163bool(true) 164bool(true) 165bool(true) 166bool(true) 167bool(true) 168bool(true) 169bool(true) 170bool(true) 171bool(true) 172bool(true) 173bool(true) 174bool(true) 175bool(true) 176bool(true) 177bool(true) 178bool(true) 179bool(true) 180bool(true) 181bool(true) 182bool(true) 183bool(true) 184bool(true) 185bool(true) 186bool(true) 187 188Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d 189bool(true) 190 191Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d 192bool(true) 193bool(true) 194bool(true) 195bool(true) 196bool(true) 197bool(true) 198bool(true) 199bool(true) 200bool(true) 201bool(true) 202bool(true) 203bool(true) 204bool(true) 205bool(true) 206bool(true) 207bool(true) 208bool(true) 209bool(true) 210bool(true) 211bool(true) 212bool(true) 213bool(true) 214bool(true) 215bool(true) 216bool(true) 217bool(true) 218bool(true) 219bool(true) 220bool(true) 221bool(true) 222bool(true) 223 224Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d 225bool(true) 226 227Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d 228bool(true) 229bool(true) 230bool(true) 231bool(true) 232bool(true) 233bool(true) 234bool(true) 235bool(true) 236bool(true) 237bool(true) 238bool(true) 239bool(true) 240bool(true) 241bool(true) 242bool(true) 243bool(true) 244bool(true) 245bool(true) 246bool(true) 247bool(true) 248bool(true) 249bool(true) 250bool(true) 251bool(true) 252 253Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d 254bool(true) 255 256Deprecated: Power of base 0 and negative exponent is deprecated in %s on line %d 257bool(true) 258bool(true) 259bool(true) 260bool(true) 261bool(true) 262bool(true) 263bool(true) 264bool(true) 265bool(true) 266bool(true) 267bool(true) 268bool(true) 269bool(true) 270bool(true) 271bool(true) 272bool(true) 273bool(true) 274bool(true) 275bool(true) 276bool(true) 277bool(true) 278bool(true) 279bool(true) 280bool(true) 281bool(true) 282bool(true) 283bool(true) 284bool(true) 285bool(true) 286bool(true) 287bool(true) 288bool(true) 289bool(true) 290bool(true) 291bool(true) 292bool(true) 293