ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 1 IDL Operators

Similar documents
GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.

Expressions and Precedence. Last updated 12/10/18

Department of Computer Science

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

Operators & Expressions

JAVA OPERATORS GENERAL

Prof. Navrati Saxena TA: Rochak Sachan

Operators. Java operators are classified into three categories:

A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.

Unit 3. Operators. School of Science and Technology INTRODUCTION

ECEN 468 Advanced Logic Design

Information Science 1

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

Data Types and Variables in C language

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Operators in java Operator operands.

SECTION II: LANGUAGE BASICS

Informatics Ingeniería en Electrónica y Automática Industrial

Macro Programming Reference Guide. Copyright 2005 Scott Martinez

Unit-2 (Operators) ANAND KR.SRIVASTAVA

Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators

COP 3275: Chapter 04. Jonathan C.L. Liu, Ph.D. CISE Department University of Florida, USA

Chapter 3: Operators, Expressions and Type Conversion

Control Structures. CIS 118 Intro to LINUX

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur

Constants and Variables

Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1

Chapter 4: Basic C Operators

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators

Language Reference Manual simplicity

Operators in C. Staff Incharge: S.Sasirekha

A flow chart is a graphical or symbolic representation of a process.

UNIT- 3 Introduction to C++

Perl: Arithmetic, Operator Precedence and other operators. Perl has five basic kinds of arithmetic:

COMP Primitive and Class Types. Yi Hong May 14, 2015

9/10/10. Arithmetic Operators. Today. Assigning floats to ints. Arithmetic Operators & Expressions. What do you think is the output?

Relational and Logical Statements

Expressions and Assignment Statements

UNIT 3 OPERATORS. [Marks- 12]

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

The Arithmetic Operators

Lecture 3. More About C

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following g roups:

ECE 122 Engineering Problem Solving with Java

LECTURE 3 C++ Basics Part 2

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

RUBY OPERATORS. Ruby Arithmetic Operators: Ruby Comparison Operators:

CSC 1214: Object-Oriented Programming

ISA 563 : Fundamentals of Systems Programming

Expression and Operator

ME 461 C review Session Fall 2009 S. Keres

In Delphi script, when values are assigned to variables, the colon-equal operator is used; :=

Learning the Language - V

Operators. Lecture 3 COP 3014 Spring January 16, 2018

Information Science 1

Lecture 3 Operators MIT AITI

SOURCE LANGUAGE DESCRIPTION

Computers Programming Course 6. Iulian Năstac

Relational and Logical Operators

CS Introduction to Data Structures How to Parse Arithmetic Expressions

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

Chapter 7. Expressions and Assignment Statements ISBN

Chapter 7. Expressions and Assignment Statements (updated edition 11) ISBN

CS313D: ADVANCED PROGRAMMING LANGUAGE

Chapter 2: Using Data

IDL 5.3. Things you need to know. On Windows, select Start > Programs -> Research Systems IDL 5.3 -> IDL Online Manuals

Chap 6 - Introduction to HDL (b)

Engineering Computing I

Chapter 7. Expressions and Assignment Statements

JAVA Programming Fundamentals

Expressions & Assignment Statements

Java Primer 1: Types, Classes and Operators

Week 3 More Formatted Input/Output; Arithmetic and Assignment Operators

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Programming. Elementary Concepts

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Recursion and Induction: Haskell; Primitive Data Types; Writing Function Definitions

Fundamentals of Programming CS-110. Lecture 3

Introduction to IDL. 1 - Basics. Paulo Penteado

Chapter 4. Operations on Data

CMSC201 Computer Science I for Majors

Objects and Types. COMS W1007 Introduction to Computer Science. Christopher Conway 29 May 2003

A Java program contains at least one class definition.

9/2/2016. Expressions are Used to Perform Calculations. ECE 120: Introduction to Computing. Five Arithmetic Operators on Numeric Types

1/31/2017. Expressions are Used to Perform Calculations. ECE 120: Introduction to Computing. Five Arithmetic Operators on Numeric Types

x= suppose we want to calculate these large values 1) x= ) x= ) x=3 100 * ) x= ) 7) x=100!

Chapter 12 Variables and Operators

Reserved Words and Identifiers

Expressions. Definitions CHAPTER 12

PieNum Language Reference Manual

Chapter 17. Fundamental Concepts Expressed in JavaScript

Operators and Expressions

Variables and literals

Chapter 4: Expressions. Chapter 4. Expressions. Copyright 2008 W. W. Norton & Company. All rights reserved.

By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

Here n is a variable name. The value of that variable is 176.

Lesson 3: Basic Programming Concepts

Chapter 4 : Informatics Practices. Data Handling. Class XI ( As per CBSE Board) Visit : python.mykvs.in for regular updates

Transcription:

ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 1 IDL Operators ARITHMATIC OPERATORS The assignment operator in IDL is the equals sign, =. IDL uses all the familiar arithmetic operators (+,, *, /) in the same manner that they are used in other programming languages. The exponent or power operator in IDL is the ^ symbol. Example: a 3 is represented as a^3 in IDL. INCREMENT AND DECREMENT OPERATORS Latter versions of IDL (6 and higher) include the increment and decrement operators (++ and ). The ++ operator adds 1 to it s operand. Example a = 3 a++ print, a => 4 The operator subtracts 1 to it s operand. Example a = 3 a print, a => 2 The increment and decrement operators ALWAYS change the value of the operand, regardless of where they occur, although it may change after it performs other operations. For example a = 3 print, a++ => 3 ;first prints value of a, then increments print, a => 4 Only one increment operator can be used at a time per variable. o Can t do (a++)++

COMPOUND OPERATORS IDL also has compound operator of the form [operator]= A statement such as b = b [operator] expression can be written equivalently as b [operator]= expression Examples of this are: a = a + b a += b a = a b a = b a = a*b a *= b a = a/b a /= b a = a^2 a ^= 2 Compound operators are just a short-hand way to write longer expressions. You don t have to use them, as you can always write out the longer version of the expressions. 2

MODULO OPERATOR To find the modulus (remainder) of two numbers, use the MOD operator, print, 5 mod 3 => 2 print, 6 mod 3 => 0 print, 3.45 mod 2 => 1.45 The modulo operator is handy for determining if one number is evenly divisible by another. If a mod b is equal to zero, then either a is zero, or a is evenly divisible by b. TRUE AND FALSE VALUES IDL doesn t have specific logical variable for true and false. Instead, it uses the following rules: Data Type True False Byte, integer, and long Odd integers Zero or even integers Floating point and complex Non-zero values Zero String Any string with non-zero length Null string ( ) RELATIONAL OPERATORS In IDL the relational operators are: eq equal to ne not equal to gt greater than ge greater than or equal to lt less than le less than or equal to 3

The relational operators return a BYTE value of 0 if they evaluate as false and a BYTE value of 1 if they evaluate as true. Examples: print, 2 eq 3 => 0 print, 2 ne 3 => 1 print, 3 lt 2 => 0 print, 3 ge 2 => 1 print, 2 ge 2 => 1 BOOLIAN (LOGICAL) OPERATORS IDL also has Boolean (logical) operators for and, or, and not. o These are && is Boolian and is Boolian or ~ is Boolian not Examples: a = 2 b = 3 print, (a eq 4) (b eq 3) => 1 print, (a eq 3) (b eq 4) => 0 print, (a eq 2) && (b eq 3) => 1 print, ~(a eq 2) => 0 IDL also has operators AND, OR, and NOT that are bit-wise operators as opposed to logical operators. The difference between the logical operators and bit-wise operators is esoteric for our purposes. You can use either, though I recommend using the &&,, and ~ forms. PRECEDENCE OF OPERATORS Operators are executed in order of priority, from highest to lowest. If two operators have the same priority, then they are executed from left to right. The table below is copied from Table 12-9 of the IDL online help. 4

Priority First (highest) Second Third Fourth Fifth Sixth Seventh Eighth Ninth Operator ( ) (parentheses, to group expressions) [ ] (brackets, to concatenate arrays). (structure field dereference) [ ] (brackets, to subscript an array) ( ) (parentheses, used in a function call) * (pointer dereference) ^ (exponentiation) ++ (increment) -- (decrement) * (multiplication) # and ## (matrix multiplication) /(division) MOD (modulus) + (addition) - (subtraction and negation) < (minimum) > (maximum) NOT (bitwise negation) ~ (logical negation) EQ (equality) NE (not equal) LE (less than or equal) LT (less than) GE (greater than or equal) GT (greater than) AND (bitwise AND) OR (bitwise OR) XOR (bitwise exclusive OR) && (logical AND) (logical OR)?: (conditional expression) Taken from Table 12-9 of IDL Online Help ADDITIONAL CONSIDERATIONS DON T GO OVERBOARD ON PARENTHESES! o If you understand the precedence of operators, there is no need to make your expressions difficult to read by using a bunch of parentheses. Example: Write y = 2.0*x^2.5*exp(-a*b/x) instead of y = (2.0*(x^(2.5)))*exp((-a*b)/x) 5

o Expressions such as y = x/(a*b) can be written without parentheses as y = x/a/b o The second expression actually executes faster on the computer, too! Whenever you are doing division, make sure at least one expression is a floating-point number. This will help you avoid the dreaded integer division problem. Write y = x*y/2.0 ; This is safe. instead of y = x*y/2 ; This is dangerous. May have integer division problem. DON T USE FLOATING POINTS FOR EXPONENTS unless you have to. Write y = x^2 instead of y = x^2.0 6