IDL出现% Program caused arithmetic error: Floating illegal operand 错误!!
2016-07-28 23:51
330 查看
用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.
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.
相关文章推荐
- 用VC进行COM编程所必须掌握的理论知识
- FlatBuffers要点
- Calling C and C++ from IDL (三) ——数组传递
- Calling C and C++ from IDL (二)——变量传递
- 如何将IDL转换成EXE(C#)
- IDL编程小技巧
- 将封装了envi功能的IDL类导出成java类,方便java调用
- IDL语言的atan2函数
- 将IDL项目创建在现存的pro文件的文件夹内
- IDL学习笔记(1)
- Ubuntu Kylin15.10下IDL8.2安装及破解步骤(含找不到libXp.so.6的解决办法,已自测通过)
- IDL与Matlab的比较
- IDL出现% Program caused arithmetic error: Floating illegal operand 错误!!
- RMI CORBA AIDL IPC RPC 之间的关系
- IDL接口定义语言教程
- Webkit Bingings 和 Java JNI 的原理与使用
- ENVI二次开发时ENVI_GET_DATA等函数的编译报错问题
- FlatBuffers使用记录(Golang)
- 接口定义语言IDL,COM
- ATL开发COM的简单实例