IDL出现% Program caused arithmetic error: Floating illegal operand 错误!!

用IDL处理NaN数据时,用到where函数时,经常会出现Program caused arithmetic error: Floating illegal operand 错误,查了下发现官网有说明,记录下防下次出错!!

Special Floating-Point Values
Machines which implement the IEEE standard for binary floating-point arithmetic have two special values for undefined results: NaN (Not A Number) and Infinity. Infinity results when a result is larger than the largest representation. NaN is the result of an undefined computation such as zero divided by zero, taking the square-root of a negative number, or the logarithm of a non-positive number. In many cases, when IDL encounters the value NaN in a data set, it treats it as “missing data.” The special values NaN and Infinity are also accessible in the read-only system variable !VALUES. These special operands propagate throughout the evaluation process—the result of any term involving these operands is one of these two special values.
Note: For the minimum (<) and maximum (>) operators with NaN operands, the result is undefined and may not necessarily be the special value NaN.
For example:
; Multiply NaN by 3
PRINT, 3 * !VALUES.F_NAN
IDL prints:
NaN
It is important to remember that the value NaN is literally not a number, and as such cannot be compared with a number. For example, suppose you have an array that contains the value NaN:
A = [1.0, 2.0, !VALUES.F_NAN, 3.0]
PRINT, A
IDL prints:
1.00000 2.00000 NaN 3.0000
If you try to select elements of this array by comparing them with a number (using the WHERE function, for example), IDL might generate an error (depending on the hardware and operating system):
; Print the indices of A that are not equal to 1
PRINT, WHERE( A NE 1.0 )
IDL prints:
1 2 3
% Program caused arithmetic error: Floating illegal operand
(Depending on your hardware and operating system, you may not see the floating-point error.)
To avoid this problem, use the FINITE function to make sure arguments to be compared are in fact valid floating-point numbers:
PRINT, WHERE( FINITE(A) )
IDL prints the indices of the finite elements of A:
0 1 3
To then print the indices of the elements of A that are both finite and not equal to 1.0, you could use the command:
good = WHERE( FINITE(A) )
PRINT, good[WHERE(A[good] NE 1.0)]
IDL prints:
1 3
Similarly, if you wanted to find out which elements of an array were not valid floating-point numbers, you could use a command like:
; Print the indices of the elements of A that are not valid
; floating-point numbers.
PRINT, WHERE( ~FINITE(A) )
IDL prints:
2
Note that the special value Infinity can be compared to a floating point number. Thus, if:
B = [1.0, 2.0, !VALUES.F_INFINITY]
PRINT, B
IDL prints:
1.00000 2.00000 Inf
and
PRINT, WHERE(B GT 1.0)
IDL prints:
1 2
You can also compare numbers directly with the special value Infinity:
PRINT, WHERE(B EQ !VALUES.F_INFINITY)
IDL prints:
2
Note: On Windows, using relational operators such as EQ and NE with the values infinity or NaN (Not a Number) causes an “illegal operand” error. The FINITE function’s INFINITY and NAN keywords can be used to perform comparisons involving infinity and NaN values. For more information, see FINITE.

你可能感兴趣的:(IDL出现% Program caused arithmetic error: Floating illegal operand 错误!!)