Columbia COMS W4115 - Control Flow (6 pages)

Previewing pages 1, 2 of 6 page document View the full content.
View Full Document

Control Flow



Previewing pages 1, 2 of actual document.

View the full content.
View Full Document
View Full Document

Control Flow

105 views


Pages:
6
School:
Columbia University
Course:
Coms W4115 - Programming Languages and Translators
Programming Languages and Translators Documents

Unformatted text preview:

Control Flow COMS W4115 Prof Stephen A Edwards Spring 2002 Columbia University Department of Computer Science Control Flow Ordering Within Expressions Time is Nature s way of preventing everything from happening at once What code does a compiler generate for Scott identifies seven manifestations of this 1 Sequencing foo bar 2 Selection if a foo 3 Iteration while i 10 foo i 4 Procedures foo 10 20 a b c d Most likely something like tmp b c a tmp d Assumes left to right evaluation of expressions 5 Recursion foo int i foo i 1 6 Concurrency foo bar 7 Nondeterminism do a foo b bar Order of Evaluation Side effects Side effects Why would you care int x 0 int x 0 int foo x 5 return x int foo x 5 return x int a foo x foo int a foo x foo Expression evaluation can have side effects Floating point numbers don t behave like numbers What s the final value of a GCC sets a 25 Sun s C compiler gave a 20 C says expression evaluation order is implementation dependent Side effects Number Behavior Misbehaving Floating Point Numbers Java prescribes left to right evaluation Basic number axioms 1e20 1e 20 1e20 class Foo static int x static int foo x 5 return x public static void main String args int a foo x foo System out println a Always prints 20 a x a if and only if x 0 Additive identity a b c a b c Associative a b c ab ac Distributive 1e 20 1e20 1 9e 7 9e 7 6 1 9e 7 9e 7 9e 7 1 so it is discarded however 1 8e 6 is large enough 1 00001 1 000001 1 6 1 00001 1 000001 1 00001 1 1 00001 1 000001 1 00001100001 requires too much intermediate precision What s Going On What s Going On Short Circuit Evaluation Floating point numbers are represented using an exponent significand format Results are often rounded When you write 1 00001000000 1 00000100000 1 10000001 z 01100000000000000000000 z 8 bit exponent 23 bit significand 1 000011 00001 z rounded if disaster could happen avoid it else cause a disaster When b c b c is small so ab ac 6 a b c because precision is lost when ab is calculated cause a



View Full Document

Access the best Study Guides, Lecture Notes and Practice Exams

Loading Unlocking...
Login

Join to view Control Flow and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Control Flow and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?