Lecture08 - 0306-381 Applied Programming • Exam One Results • Floating-Point Algorithm Summary • Number Representations • Fixed-Point

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 0306-381 Applied Programming • Exam One Results • Floating-Point Algorithm Summary • Number Representations • Fixed-Point Numbers Floating-Point Multiplication: C ¬ A ´ B Generate Significands of A and B: If Exponent is 0? Þ 0 Otherwise Þ 1 concatenated with Fraction Compute Sign of C: XOR signs of A and B Compute Exponent of C: Add unbiased Exponents and then bias Compute Significand of C: Multiply Significands of A and B Truncate extra fractional bits Normalize, if necessary: If there is a second integer bit >>= 1 Exponent++ Assign Fraction of C 2 Floating-Point Division: C ¬ A ¸ B “Approximation” Implementation Approximate reciprocal of B Multiply A and reciprocal of B 3 Floating-Point Additon: C ¬ A + B Page 1 of 2 Generate Significands of A and B: If Exponent is 0? Þ 0 Otherwise Þ 1 concatenated with Fraction Compute Sign of C: (Maybe change Significand) Do A and B have same sign? Þ same as A and B Otherwise: Þ same as sign of larger Is A Exponent larger than B Exponent? Þ A larger Is B Exponent larger than A Exponent? Þ B larger Otherwise (Exponents are equal): Is A Significand larger than B Significand? A larger also Negate B Significand Is B Significand larger than A Significand? B larger also Negate A Significand Otherwise numbers are equal 4 Floating-Point Additon: C ¬ A + B Page 2 of 2 Compute Exponent of C: Larger of A and B Exponents Align smaller of A or B Compute Significand of C: Add Significands of A and B Normalize, if necessary: If there is a second integer bit >>= 1 Exponent++ Otherwise, while integer bit is 0 <<= 1 Exponent-Assign Fraction of C 5 Floating-Point Subtraction: C ¬ A - B Negate B Add A and negative of B 6 0306-381 Applied Programming üExam One Results üFloating-Point Algorithm Summary FNumber Representations • Fixed-Point Numbers Numerical Algorithms • C intrinsic types – int – float • Algorithm characteristics Iterate until “close enough” to solution – Is within 0.5 close enough? – Is within 1´10-12 close enough? – Is within 1´10-500 close enough? 8 Number Representation • Resolution – Fine-grain limit of representation – Minimum difference between two numbers • Range – Course-grain limit of representation – Maximum difference between two numbers Dependent on formats – Number of bits – Components/Fields 9 Integer Representations • int – Resolution: 1 – Range: [-231, 231 - 1] • unsigned int – Resolution: 1 – Range: [0, 232 - 1] • short int – Resolution: 1 – Range: [-215, 215 - 1] • unsigned short int – Resolution: 1 – Range: [0, 216 - 1] • long int – Resolution: 1 – Range: [-263, 263 - 1] • unsigned long int – Resolution: 1 – Range: [0, 264 - 1] • char – Resolution: 1 – Range: [-27, 27 - 1] • unsigned char – Resolution: 1 – Range: [0, 28 - 1] 10 Floating-Point Representations • float – Resolution • Normalized: 1.17549´10-38 • De-normalized: 1.4013´10-45 – Range: ±3.40282´10+38 • double – Resolution • Normalized: 2.22507´10-308 • De-normalized: 4.94066´10-324 – Range: ±1.79769´10+308 11 Language and Platform • C and C++ ranges and resolutions – Platform-specific – x86 values on previous slides • Other languages’ ranges and resolutions May be more rigid with intrinsic types (i.e., platform-independent) 12 Additional number representations • Suppose want resolution of 0.03 – int too large int will not work. – float too small float works. • Custom data types – Resolution unsupported by platform For example, no floating-point hardware – Performance unsupported by intrinsic types For example, floating-point too slow 13 IEEE 754 Floating-Point Number Representation • Floating-point standard • Four floating-point formats – Single precision 32 bits – Double precision 64 bits – Extended single precision • ³ 32 bits • Typically 40 or 48 bits – Extended double precision • ³ 64 bits • Typically 80 or 128 bits 14 0306-381 Applied Programming üExam One Results üFloating-Point Algorithm Summary üNumber Representations FFixed-Point Numbers Intrinsic Number Formats • Integer – Need fractional data representation – Not sufficient for all numerical methods • Floating point – Special hardware Slower than integer – Software libraries • Slower than floating-point hardware • Larger code size—algorithmic complexity 16 Alternative If you can’t find a solution to a problem, change focus to a question you can solve. • Problem – Need floating-point characteristics – Avoid floating-point numbers How can integers be used to get needed floating-point characteristics? 17 Scaled Integers • Fixed point • Q format – Type: integer Q – Interpretation: divided by 2 • Q6 • Q15 Ambiguous without specification of word size. Only in mind of programmer— never calculated. – Choice: word size (N) • Fastest available • Minimum size Choose based on application and machine. 18 Q-Format Characteristics • Data type to meet needs of application • Range (N-bit word) – Signed: [-2N-1-Q, 2N-1-Q - 2-Q] -Q N-Q – Unsigned: [0, 2 - 2 ] – Smallest possible value – 2-Q – Uniform across entire range Unlike FP • Resolution 19 Some Q-Format Applications • OpenGL ES 1.x specification • VisSim—simulation and system design software • GnuCash—open-source accounting software • Tremor and Toast—audio codecs • Sony’s original PlayStation 3-D graphics engine • Sega’s Saturn • Nintendo’s Game Boy Advance (2-D) game system • Nintendo DS (2-D and 3-D) game system • Fracint—open-source fractal package • TeX font metric (signed 32-bit Q12) • PostgreSQL—object-relational DBMS Source: “Fixed-point arithmetic,” Wikipedia, http://en.wikipedia.org/wiki/Fixed-point_arithmetic, Mar. 31, 2010. 20 Q-Format Summary • Resolution: determined by Q • Range: determined by N and Q • N and Q: – Application – Target machine 21 ...
View Full Document

This note was uploaded on 04/27/2010 for the course EECC 0306-381 taught by Professor Roymelton during the Spring '10 term at RIT.

Ask a homework question - tutors are online