Skip to content

abs

Absolute value

abs x    abs[x]

Where x is a numeric, returns the absolute value of x. x is returned if x is null. abs also works with temporal values, where it operates on the underlying numeric (refer to the examples below).

q)abs -1.0
1f
q)abs 10 -43 0N
10 43 0N
q)abs 1999.01.01
2000.12.31

q)/ If we convert these to longs, we can observe they're opposite
q)"j"$1999.01.01 2000.12.31 
-365 365

abs is a multithreaded primitive.

Implicit iteration

abs is an atomic function.

q)abs(10;20 -30)
10
20 30

It applies to dictionaries and tables.

Domain and range

The following shows the resulting output (range) type given the input (domain) type of x. For the character codes of the datatypes, refer to Datatypes.

domain b g x h i j e f c s p m d z n u v t
range  i . i h i j e f i . p m d z n u v t

Range: ihjefpmdznuvt


signum

Mathematics