Skip to main content

This is documentation for Caché & Ensemble. See the InterSystems IRIS version of this content.

For information on migrating to InterSystems IRIS, see How to Migrate to InterSystems IRIS, available on the WRC Distributions page (login required).

NEGS

Returns the inverse sign of each number in a dynamic array.

Synopsis

NEGS(dynarray)

Arguments

dynarray An expression that resolves to a dynamic array of numeric values. Its elements can contain values specified as a number or a numeric string.

Description

The NEGS function inverts the sign of each numeric element of dynarray. These output values are returned as a dynamic array. A value of 1 is returned as -1, and a value of -1 is returned as 1. NEGS returns numbers (both numerics and numeric strings) in canonical form, removing multiple signs and leading and trailing zeros from each value. A string is parsed as a number until a non-numeric character is encountered. Thus “7dwarves” is parsed as 7, and returns -7. If an element value is missing or has an empty string or non-numeric value, NEGS returns 0 (zero).

The NEGS function inverts the sign of each number in a dynamic array: negative numbers become positive and positive numbers become negative. The ABSS function gives the absolute value of each number in a dynamic array: all numbers become positive.

You can use the NEG function to invert the sign of a single number.

Examples

The following example uses the NEGS function to invert the sign of each number in a dynamic array:

nums=123:@VM:-12.300:@VM:++0123.00:@VM:"-123.00":@VM:""
PRINT NEGS(nums)  ! Returns -123ý12.3ý-123ý123ý0

See Also

Feedback