Requires the Hack Standard Library to be installed.
Facebook Engineer?

This function is available as Math\abs() in Facebook's www repository.

Returns the absolute value of $number ($number if $number > 0, -$number if $number < 0)

namespace HH\Lib\Math;

function abs<T as num>(
  T $number,
): T;

NB: for the smallest representable int, PHP_INT_MIN, the result is "implementation-defined" because the corresponding positive number overflows int. You will probably find that Math\abs(PHP_INT_MIN) === PHP_INT_MIN, meaning the function can return a negative result in that case. To ensure an int is non-negative for hashing use $v & PHP_INT_MAX instead.


  • T $number


  • T