Sign

Sign( value )
Sign( value )
Sign( value )
Sign( value )
sign( value )
Sign( value )

Description

The Sign function returns the sign of the value parameter as a numeric value.

Parameters

Parameter Type Definition and Requirements

value

Determine the sign of this Number.

Returns

Long Values:

  • 1 when the value of the argument is positive.

  • 0 when the value of the argument is zero.

  • -1 when the value of the argument is negative.

Double Values:

  • -1 when the value of the argument is less than zero.

  • 1 when the value is greater than or equal to zero or NaN.

Examples

The following query executes an array of independent sign operations and returns the results in an array. The result array position matches the execution array position. The first sign operation on the value 3 returns 1 for a positive number. The second operation returns zero for neither a positive nor negative number. The third sign operation on the value -3 returns -1 for a negative number.

try
{
    Value result = await client.Query(
        Arr(
            Sign(3),
            Sign(0),
            Sign(-3)
        )
    );
    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
Arr(LongV(1), LongV(0), LongV(-1))
result, err := client.Query(
	f.Arr{
		f.Sign(3),
		f.Sign(0),
		f.Sign(-3),
	})

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
[1 0 -1]
System.out.println(
    client.query(
        Arr(
            Sign(Value(3)),
            Sign(Value(0)),
            Sign(Value(-3))
        )
    ).get());
[1, 0, -1]
client.query([
  q.Sign(3),
  q.Sign(0),
  q.Sign(-3),
])
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
[ 1, 0, -1 ]
result = client.query(
  [
    q.sign(3),
    q.sign(0),
    q.sign(-3),
  ]
)
print(result)
[1, 0, -1]
[
  Sign(3),
  Sign(0),
  Sign(-3)
]
[ 1, 0, -1 ]
Query metrics:
  •    bytesIn:  35

  •   bytesOut:  21

  • computeOps:   1

  •    readOps:   0

  •   writeOps:   0

  •  readBytes:   0

  • writeBytes:   0

  •  queryTime: 2ms

  •    retries:   0

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!