3v4l.org

run code in 300+ PHP versions simultaneously
<?PHP include 'pyhp.php'; if (!function_exists('gmp_sign')) { function gmp_sign($x) { return ($x<0?-1:1); } } function assertx($assertion, $failure="Assertion failed", $throwexception=true, $exception="ErrorException") { $assert_options = array(ASSERT_WARNING => 0, ASSERT_BAIL => 0, ASSERT_QUIET_EVAL => 1); foreach ($assert_options as $opt => $val) { $origval = assert_options($opt, $val); $assert_options[$opt] = $origval; } $test = assert($assertion); foreach ($assert_options as $opt => $val) { assert_options($opt, $val); } if ($test) return true; if (!$test) { if ($throwexception) throw new $exception($failure); return false; } } $xr = pyrange(-1, 1, 0.1); $yr = pyrange(-1, 1, 0.2); $eq = function($x, $y) { $c = function($i) { return $i*(180/pi()); }; $x = $c($x); $y = $c($y); if ($y == 0) return 90*gmp_sign($x); $a = round(180-$c(atan($x/$y)),0); if (gmp_sign($y) == -1) { $a -= 180; } return $a; }; assertx(gmp_sign(-0.5).'==-1'); assertx($eq(1, 1).'==135'); echo $eq(1, 1); echo PHP_EOL; echo $eq(-1, 1); echo PHP_EOL; echo $eq(-1, -1); echo PHP_EOL; echo $eq(1, -1); ?>

preferences:
62.43 ms | 402 KiB | 5 Q