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.
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
"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
A = COMPLEX(1,2) < COMPLEX(2,-4)
A = COMPLEX(1,-2) < COMPLEX(-2,1)
Maximum Operator Examples
A = COMPLEX(1,2) > COMPLEX(2,-4)
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
PRINT, A > B
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]