The IDL minimum and maximum operators return the smaller or larger of their operands, as described below.

Note: Negated values must be enclosed in parentheses in order for IDL to interpret them correctly.

Note: If one or both of the operands are objects, the operator may be overloaded.

Operator

Description

Example

<

Minimum operator.
The value of "A < B" is equal to the smaller of A or B.

Set A equal to 3:

A = 5 < 3

Set A equal to -6. Use parentheses to avoid a syntax error.

A = 5 < (-6)

Set all points in array ARR that are larger than 100 to 100:

ARR = ARR < 100

Set X to the smallest of the three operands:

X = X0 < X1 < X2

>

Maximum operator.
"A > B" is equal to the larger of A or B.

Use '>' to avoid taking the log of zero or negative numbers:

C = ALOG(D > 1E - 6)

Plot positive points only. Negative points are plotted as zero:

PLOT, ARR > 0

Using Minimum or Maximum with Signed and Unsigned Integers


When using the minimum and maximum operators with signed and unsigned integers, you should be careful of automatic type conversions. With signed and unsigned integers of the same size (16, 32, or 64 bits), the left operand determines the result type. For example: 5 < 65535u will give –1 since the 65535 will be converted to a signed integer first. On the other hand, 65535u < 5 will give 5 since the 5 will be converted to an unsigned integer. For more details on automatic type conversions see Data Type and Structure of Expressions.

Using Minimum or Maximum with Complex Numbers


For complex numbers, the absolute value is used to determine which value is smaller or larger. If both values have the same magnitude then the first value is returned.

Minimum Operator Examples

; Set A equal to 1+2i, since ABS(1+2i) is less than ABS(2-4i):
A = COMPLEX(1,2) < COMPLEX(2,-4)
; Set A equal to 1-2i, since ABS(1-2i) equals ABS(-2+i):
A = COMPLEX(1,-2) < COMPLEX(-2,1)

Maximum Operator Examples

; Set A equal to 2-4i, since ABS(2-4i) is greater than ABS(1+2i)
A = COMPLEX(1,2) > COMPLEX(2,-4)
 
; Set A equal to 1-2i, since ABS(1-2i) equals ABS(-2+i)
A = COMPLEX(1,-2) > COMPLEX(-2,1)

Using Minimum or Maximum with NaN Values


Typically in IDL, the result of any operation involving the special value NaN is NaN. For efficiency, IDL does not check the values of A and B for NaN values before performing the minimum or maximum operation. If A or B contains a NaN value, the result is undefined and can be either NaN or the other non-NaN value, depending on the specific hardware and operating system. If you suspect that one of your operands contains NaN values, you might want to use the FINITE function to ensure that you return NaN values in the result. For example, if A and B are scalars:

A = !VALUES.F_NAN
B = 5
 
; Result is undefined and can either be 5 or NaN:
PRINT, A > B
 
; Result must be NaN if either operand is NaN:
PRINT, ( FINITE(A) && FINITE(B) ) ? ( A > B ) : !VALUES.F_NAN

This second method also avoids any floating-point math errors. If A and B are arrays, the following method can be used:

C = REPLICATE( !VALUES.F_NAN, N_ELEMENTS(A) )
good = WHERE( FINITE(A) and FINITE(B), ngood )
IF ( ngood GT 0 ) THEN C[good] = A[good] > B[good]