HomeManualTopicsTypesSymbols

std::sgn

returns the sign of its (numerical) argument

Parameter

value
the value to determine the sign of

Result

result
-1, 0, or 1

Description

If the argument is less than zero then -1 is returned.

If the argument equals zero then 0 is returned.

If the argument is greater than zero then 1 is returned.

Example

println! sgn(-123)

Output

-1

Example

println! sgn(0)

Output

0

Example

println! sgn(123)

Output

1

Topic

Math

See also

std::abs returns the absolute value of its (numerical) argument