This preview shows page 1. Sign up to view the full content.
Unformatted text preview: 0306381 Applied Programming • Exam One Results • FloatingPoint Algorithm Summary • Number Representations • FixedPoint Numbers FloatingPoint 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 FloatingPoint Division: C ¬ A ¸ B “Approximation” Implementation
Approximate reciprocal of B Multiply A and reciprocal of B 3 FloatingPoint 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 FloatingPoint 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 ExponentAssign Fraction of C 5 FloatingPoint Subtraction: C ¬ A  B
Negate B Add A and negative of B 6 0306381 Applied Programming üExam One Results üFloatingPoint Algorithm Summary FNumber Representations • FixedPoint 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´1012 close enough? – Is within 1´10500 close enough? 8 Number Representation
• Resolution
– Finegrain limit of representation – Minimum difference between two numbers • Range
– Coursegrain 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 FloatingPoint Representations
• float
– Resolution
• Normalized: 1.17549´1038 • Denormalized: 1.4013´1045 – Range: ±3.40282´10+38 • double
– Resolution
• Normalized: 2.22507´10308 • Denormalized: 4.94066´10324 – Range: ±1.79769´10+308 11 Language and Platform
• C and C++ ranges and resolutions
– Platformspecific – x86 values on previous slides • Other languages’ ranges and resolutions
May be more rigid with intrinsic types (i.e., platformindependent) 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 floatingpoint hardware – Performance unsupported by intrinsic types
For example, floatingpoint too slow 13 IEEE 754 FloatingPoint Number Representation
• Floatingpoint standard • Four floatingpoint 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 0306381 Applied Programming üExam One Results üFloatingPoint Algorithm Summary üNumber Representations FFixedPoint 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 floatingpoint 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 floatingpoint characteristics – Avoid floatingpoint numbers How can integers be used to get needed floatingpoint 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 QFormat Characteristics
• Data type to meet needs of application • Range (Nbit word)
– Signed: [2N1Q, 2N1Q  2Q] Q NQ – Unsigned: [0, 2  2 ] – Smallest possible value – 2Q – Uniform across entire range
Unlike FP • Resolution 19 Some QFormat Applications
• OpenGL ES 1.x specification • VisSim—simulation and system design software • GnuCash—opensource accounting software • Tremor and Toast—audio codecs • Sony’s original PlayStation 3D graphics engine • Sega’s Saturn • Nintendo’s Game Boy Advance (2D) game system • Nintendo DS (2D and 3D) game system • Fracint—opensource fractal package • TeX font metric (signed 32bit Q12) • PostgreSQL—objectrelational DBMS
Source: “Fixedpoint arithmetic,” Wikipedia, http://en.wikipedia.org/wiki/Fixedpoint_arithmetic, Mar. 31, 2010. 20 QFormat 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 0306381 taught by Professor Roymelton during the Spring '10 term at RIT.
 Spring '10
 RoyMelton

Click to edit the document details