1 数学运算符
1.1增运算和减运算(++、- -)
IDL> var = 20
IDL> print,var++
20
IDL> print,var
21
1.2幂运算(^)
IDL> var = 2
IDL> print,var^4
16
IDL> print,var^5
32
IDL> var = [2,3]
IDL> print,var^2
4 9
1.3取余运算(mod)
IDL> var = 32
IDL> print,var mod 4
0
IDL> print,var mod 5
2
IDL> var = [2,3]
IDL> print,var mod 2
0 1
1.4取大和取小运算(> 、<)
IDL> var = 32
IDL> print,var > 39
39
IDL> print,var < 39
32
IDL> var = [20,30]
IDL> print,var >25
25 30
2 逻辑运算符
IDL中逻辑运算有几个:&&, ||, 和 ~。
2.1&&(与)逻辑的与运算
如果表达式为真或非零则返回1否则返回0。
IDL> PRINT, 5 && 2
1
IDL> PRINT, 5 && 0
0
IDL> PRINT, "sd" && "d"
1
IDL> PRINT, "sd" && " "
1
IDL> PRINT, "sd" && ""
0
2.2||(或)逻辑的或运算
IDL> PRINT, 5 || 2
1
IDL> PRINT, 5 || 0
1
IDL> PRINT, 0 || 0
0
2.3~(非)逻辑的非运算
IDL> print,~3
0
IDL> print,~0
1
3 位运算符
IDL中有四个位运算符:AND, NOT, OR, and XOR.
3.1位加运算符(AND)
IDL> print,5 AND 6
4
0110 ← 5
0111 ← 6
0110 ← 4
3.2位取反运算符(NOT)
IDL> print,not 1
-2
3.3位或运算符(OR)
IDL> print,5 or 10
15
0101 ← 5
1010 ← 10
1111 ← 15
3.4位与或运算符(XOR)
IDL> print,3 XOR 5
6
0011 ← 3
0110 ← 5
0110 ← 6
4 关系运算符
IDL中的关系运算符包括EQ、NE、GE、GT、LE、LT几个,关系运算符返回的是真“True”或假“False”.
4.1EQ(Equal to)
等运算符,如果运算符两边相同则返回真,否则返回假;
IDL> print,2 EQ 2.0
1
IDL> var = [2,3]
IDL> print,var eq 2
1 0
4.2NE(Not Equal to)
不等运算符,如果运算符两边不等则返回真,否则返回假;
IDL> print,2 NE 2.0
0
IDL> print,2 NE 1
1
IDL> var = [2,3]
IDL> print,var ne 2
0 1
4.3 GE(Greater than or equal to)
大于等于运算符,如果运算符两边左边大于等于右边则返回真,否则返回假;
IDL>print,2 GE 1
1
IDL> var = [2,3]
IDL> print,var ge 2
1 1
4.4 GT(Greater than)
大于运算符,如果运算符两边左边大于右边则返回真,否则返回假;
IDL> print,2 GT 1
1
IDL> var = [2,3]
IDL> print,var gt 2
0 1
4.5LE(Less than or equal to)
小于等于运算符,如果运算符两边左边小于等于右边则返回真,否则返回假;
IDL> print,2 LE 1
0
IDL> print,2 LE 12
1
IDL> var = [2,3]
IDL> print,var le 3
1 1
4.6 LT(Less than)
小于运算符,如果运算符两边左边大于右边则返回真,否则返回假;
IDL> rint,2 LT 1
0
IDL> print,2 LT 12
1
IDL> print,2 LT 2
0
IDL> var = [2,3]
IDL> print,var lt 3
1 0
4.7 数组间运算
IDL> a =[2,3,5]
IDL> b = [1,4,5]
IDL> print,a GE b
1 0 1
IDL> b = [1,4,5,6]
IDL> print,a GE b
1 0 1
IDL> print,a LE b
0 1 1
5 数组运算符
5.1#(数组乘,列乘行)
IDL> PRINT, array1
1 2 1
2 -1 2
IDL> PRINT, array2
1 3
0 1
1 1
IDL> PRINT, array1#array2
7 -1 7
2 -1 2
3 1
5.2##(矩阵乘,行乘列)
IDL> PRINT, array1
1 2 1
2 -1 2
IDL> PRINT, array2
1 3
0 1
1 1
IDL> PRINT, array1##array2
2 6
4 7
6 其他运算符
6.1小括号()
表达式组合和控制一系列表达式的优先级;
IDL> PRINT, 3 + 4 * 2 ^ 2 /2
11
IDL> PRINT, (3 + (4 * 2) ^ 2 / 2)
35
6.2中括号[]
数组的连接或元素调用;
IDL> C = [0, 1, 3]
IDL> PRINT, [C, 5]
0 1 3 5
IDL> PRINT, C[2]
3
6.3条件表达式? :
该运算符的用法是:value = expr1 ? expr2 : expr3
如果expr1是true,那么 value 等于expr2否则value = expr3.
IDL> A=6 & B=4
IDL> print,(A GT B) ? A : B
6
6.4对象方法调用符->
oWindow->Draw
6.5指针引用符*
指针调用符为,调用格式为指针变量。
IDL> point1 = ptr_New(34)
IDL> print,*point1
简单书写,
希望你十分美好!
网友评论