Skip to main content
Commonmark migration
Source Link

PHP, 39 38 bytes

##no comparison operators

no comparison operators

<?=($n=$argv[1])&PHP_INT_MIN?-1:1-!$n;

should work on most systems.

PHP_INT_MIN has only one bit set: the most significant one. If this is set in the input, it is negative.
!$n (cast to integer by the subtraction) evaluates to 0 for positive values and 1 for 0.

lame solution, 30 bytes

<?=($n=$argv[1])?abs($n)/$n:0;

works also on floats.

PHP, 39 38 bytes

##no comparison operators

<?=($n=$argv[1])&PHP_INT_MIN?-1:1-!$n;

should work on most systems.

PHP_INT_MIN has only one bit set: the most significant one. If this is set in the input, it is negative.
!$n (cast to integer by the subtraction) evaluates to 0 for positive values and 1 for 0.

lame solution, 30 bytes

<?=($n=$argv[1])?abs($n)/$n:0;

works also on floats.

PHP, 39 38 bytes

no comparison operators

<?=($n=$argv[1])&PHP_INT_MIN?-1:1-!$n;

should work on most systems.

PHP_INT_MIN has only one bit set: the most significant one. If this is set in the input, it is negative.
!$n (cast to integer by the subtraction) evaluates to 0 for positive values and 1 for 0.

lame solution, 30 bytes

<?=($n=$argv[1])?abs($n)/$n:0;

works also on floats.

added another version
Source Link
Titus
  • 14.8k
  • 1
  • 24
  • 41

PHP, no comparison operators, 39 38 bytes

##no comparison operators

<?=($n=$argv[1])&PHP_INT_MIN?-1:1-!$n;

should work on most systems.

PHP_INT_MIN has only one bit set: the most significant one. If this is set in the input, it is negative.
!$n (cast to integer by the substractionsubtraction) evaluates to 0 for positive values and 1 for 0.

lame solution, 30 bytes

<?=($n=$argv[1])?abs($n)/$n:0;

works also on floats.

PHP, no comparison operators, 39 38 bytes

<?=($n=$argv[1])&PHP_INT_MIN?-1:1-!$n;

should work on most systems.

PHP_INT_MIN has only one bit set: the most significant one. If this is set in the input, it is negative.
!$n (cast to integer by the substraction) evaluates to 0 for positive values and 1 for 0.

PHP, 39 38 bytes

##no comparison operators

<?=($n=$argv[1])&PHP_INT_MIN?-1:1-!$n;

should work on most systems.

PHP_INT_MIN has only one bit set: the most significant one. If this is set in the input, it is negative.
!$n (cast to integer by the subtraction) evaluates to 0 for positive values and 1 for 0.

lame solution, 30 bytes

<?=($n=$argv[1])?abs($n)/$n:0;

works also on floats.

fixed grammar
Source Link
Titus
  • 14.8k
  • 1
  • 24
  • 41

PHP, no comparison operators, 39 38 bytes

<?=($n=$argv[1])&PHP_INT_MIN?-1:1-!$n;

Not using comparison operators. Shouldshould work on most systems.

PHP_INT_MIN has only one bit set: the most significant one. If this is set in the input, the inputit is negative. 
!$n casts(cast to integer, by the substraction) evaluates to 0 for positive values and 1 for 0.

PHP, 39 38 bytes

<?=($n=$argv[1])&PHP_INT_MIN?-1:1-!$n;

Not using comparison operators. Should work on most systems.

PHP_INT_MIN has only one bit set: the most significant one. If this is set in the input, the input is negative. !$n casts to integer, evaluates to 0 for positive values and 1 for 0.

PHP, no comparison operators, 39 38 bytes

<?=($n=$argv[1])&PHP_INT_MIN?-1:1-!$n;

should work on most systems.

PHP_INT_MIN has only one bit set: the most significant one. If this is set in the input, it is negative. 
!$n (cast to integer by the substraction) evaluates to 0 for positive values and 1 for 0.

Fixed grammar, avoid additional text in the heading
Source Link
user344
user344
Loading
golfed 1 byte by calculating 0/positive instead of using a ternary.
Source Link
Titus
  • 14.8k
  • 1
  • 24
  • 41
Loading
Source Link
Titus
  • 14.8k
  • 1
  • 24
  • 41
Loading