CSC161 2010F, Class 14: Operators and Precedence Overview: * IEEE Floating Point, Continued. * C's Wealth of Operators. * Some Precedence and Other Examples. * Group Exercise. Admin: * Warning: Your class mentor will be unavailable most of next week. * Don't forget the Town Hall meetings today! (Noon and 7:30) * Reading for tomorrow: 3.1-3.3. * Reminder: Review session Friday! * Take-home exam distributed Wednesday, due the following Wednesday. INDIVIDUAL work. * Are there questions on Assignment 4? I know that some of you have questions about stacks. Questions on Assignment 4 * The algorithm for part 2: Start with an "empty" array of some fixed size For each remaining value in the input * If it's a number, add it to the "end" of the array * If you see an operator, remove the parameters from the "end" of the array, evaluate the operator, and put the result back in the array. * What do you mean by "push" and "pop" * Pop means "remove from the end" * Push means "add to the end" * Do we know that the input is divided by spaces? * No, but you can assume the input is separate strings, so life is okay. * Can we add an extra parameter to rpn that takes the position we start at in the array? * Yes. * Why would we want to do that? * So that we can ignore the first element of argv rpn (size, array_of_strings) rpn (size, array_of_strings, start_here) * Bring more questions tomorrow! IEEE Floating Point, Continued * Effectively, exponential notation in binary Three parts: * Sign * Significand * Exponent * Designer of such a notation needs to decide * How many bits for each part * How to represent each part * How to deal with special cases * Sign: 1 bit * How should we distribute the remaining 31 bits * E.g., 15 bits for significand and 16 bits for exponent * If exponent can be positive or negative, the largest possible exponent is about 2^15 and the smallest possible exponent is about -(2^15) * 1/2^15 is the accuracy - about 1/32thousand - four or five significant digits * The IEEE committee decided * 8 bits for the exponent * 23 bits for the significand (virtually 24) * How do you represent each part? * Decision for exponent: Excess 127 So exponent -127 could be represented as 00000000 And exponent 0 is represented as 01111111 Smallest legal exponent -126 Largest legal exponent 127 Note 00000000 and 11111111 are not legal exponents * These are used for other special values All 0's: Significand is interpreted as between 0 and 1, permitting us to represent 0 (and some other small numbers), treat exponent as -127 (0 is therefore all 0's) All 1's If the significand is all 0's, it's infinity Otherwise, it's Not a Number (NaN) Next Topic: Operations in C * C provides a lot of operations * Two-parameter Arithmetic operations: -, +, *, /, % (modulo) * Two-parameter Bitwise operations: |, &, ^ (exclusive or) * Two-parameter Binary operations: <<, >> * Two-parameter Assignment Operations: =, +=, -=, *=. <<=, /=, %= * Two-parameter logical operations: ==, !=, <, <=, >, >=, &&, || * One-parameter Arithmetic operations: -, ++, --, + -x means "negate x" * One-parameter Bitwise operations: ~ * One-parameter logical operations: ! * Typical issue with operators: Precedence! 3 + 4 * 5 * C does pay attention to precedence Precedence * Some examples Exercise