Download presentation

Presentation is loading. Please wait.

Published byJayden Lavin Modified over 2 years ago

1
14-1 Bard, Gerstlauer, Valvano, Yerraballi EE 319K Introduction to Embedded Systems Lecture 14: Gaming Engines, Coding Style, Floating Point

2
14-2 Bard, Gerstlauer, Valvano, Yerraballi Agenda Recap Software design 2-D arrays, structs Bitmaps, sprites Lab 10 Agenda Gaming engine design Coding style Floating point

3
14-3 Bard, Gerstlauer, Valvano, Yerraballi Numbers Integers ( ℤ ): universe is infinite but discrete No fractions No numbers between 5 and 6 A countable (finite) number of items in a finite range Real numbers ( ℝ ): universe is infinite & continuous Fractions represented by decimal notation oRational numbers, e.g., 5/2 = 2.5 oIrrational numbers, e.g., ~ 22/7 = Infinity of numbers exist even in the smallest range (Adapted from V. Aagrawal)

4
14-4 Bard, Gerstlauer, Valvano, Yerraballi Number Representation Integers Fixed-width integer number Reals Fixed-point number I oStore I, but is fixed oDecimal fixed-point (=10 m ) = I 10 m oBinary fixed-point (=2 m ) = I 2 m Floating-point number = I B E oStore both I and E (only B is fixed)

5
14-5 Bard, Gerstlauer, Valvano, Yerraballi Wide Range of Real Numbers A large number: 976,000,000,000,000 = A small number: = No fixed that can represent both Not representable in single fixed-point format (Adapted from V. Aagrawal)

6
14-6 Bard, Gerstlauer, Valvano, Yerraballi Floating Point Numbers Decimal scientific notation 0.513×10 5, 5.13×10 4 and 51.3×10 3 5.13×10 4 is in normalized scientific notation Binary floating point numbers Base B = 2 Binary point oMultiplication by 2 moves the point to the left Normalized scientific notation, e.g., 1.0×2 -1 oKnown as floating point numbers (Adapted from V. Agrawal)

7
14-7 Bard, Gerstlauer, Valvano, Yerraballi Normalizing Numbers In scientific notation, we generally choose one digit to the left of the decimal point × becomes × Normalizing means Shifting the decimal point until we have the right number of digits to its left oNormally one Adding or subtracting from the exponent to reflect the shift (Adapted from V. Agrawal)

8
14-8 Bard, Gerstlauer, Valvano, Yerraballi Floating Point Numbers General format ±1.bbbbb two ×2 eeee or(-1) S × (1+F) × 2 E Where S = sign, 0 for positive, 1 for negative F = fraction (or mantissa) as a binary integer, 1+F is called significand E = exponent as a binary integer, positive or negative (two’s complement) (Adapted from V. Agrawal)

9
14-9 Bard, Gerstlauer, Valvano, Yerraballi ANSI/IEEE Std Single-precision float format (Adapted from V. Agrawal) Bit 31Mantissa sign, s=0 for positive, s=1 for negative Bits 30:238-bit biased binary exponent 0 ≤ e ≤ 255 Bits 22:024-bit mantissa, m, expressed as a binary fraction, A binary 1 as the most significant bit is implied. m = 1.m 1 m 2 m 3...m 23

10
14-10 Bard, Gerstlauer, Valvano, Yerraballi IEEE 754 Floating Point Standard Biased exponent: exponent range [-127,127] changed to [0, 255] Biased exponent is an 8-bit positive binary integer True exponent obtained by subtracting or 255 = special case First bit of significand is always 1: ± 1.bbbb... b × 2 E 1 before the binary point is implicitly assumed oSo we don’t need to include it – just assume it’s there! Significand field is 23 bit fraction after the binary point Significand range is [1, 2) Standard formats: Single precision: 8 (E) + 23 (F) + 1 (S) = 32 bits ( float ) Double precision: 11 (E) + 52 (F) + 1 (S) = 64 bits ( double ) (Adapted from V. Agrawal)

11
14-11 Bard, Gerstlauer, Valvano, Yerraballi Negative Overflow Positive Overflow Expressible numbers Numbers in 32-bit Formats Two’s complement integers Floating point numbers The range is larger, but the number of numbers per unit interval is less than that for a comparable fixed point range Expressible negative numbers Expressible positive numbers Positive underflow Negative underflow (2 – )× (2 – )×2 127 (Adapted from V. Agrawal)

12
14-12 Bard, Gerstlauer, Valvano, Yerraballi Binary to Decimal Conversion Binary(-1) S (1.b 1 b 2 b 3 b 4 ) × 2 E Represents(-1) S × (1 + b 1 × b 2 × b 3 × b 4 ×2 -4 ) × 2 E Example: × 2 -2 (binary)= - ( ) ×2 -2 = - ( )/4 = /4 = (decimal) (Adapted from V. Agrawal)

13
14-13 Bard, Gerstlauer, Valvano, Yerraballi Decimal to Binary Conversion Converting from base 10 to the representation Single precision example Covert Step 1 – convert to binary In a binary representation form of 1.xxx have = x 2 6

14
14-14 Bard, Gerstlauer, Valvano, Yerraballi Decimal to Binary Conversion (cont’d) x 2 6 is binary for 100 Thus the exponent is a 6 Biased exponent will be 6+127=133 = Sign will be a 0 for positive Stored fractional part f will be 1001 Thus we have S E F …. 4 2 C in hexadecimal $42C is representation for 100

15
14-15 Bard, Gerstlauer, Valvano, Yerraballi Positive Zero in IEEE 754 × Smallest positive number in single-precision IEEE 754 standard. Interpreted as positive zero. Exponent less than -127 is positive underflow; can be regarded as zero Biased exponent Fraction (Adapted from V. Agrawal)

16
14-16 Bard, Gerstlauer, Valvano, Yerraballi Negative Zero in IEEE 754 × Smallest negative number in single-precision IEEE 754 standard. Interpreted as negative zero. True exponent less than -127 is negative underflow; may be regarded as Biased exponent Fraction (Adapted from V. Agrawal)

17
14-17 Bard, Gerstlauer, Valvano, Yerraballi Positive Infinity in IEEE 754 × Largest positive number in single-precision IEEE 754 standard. Interpreted as + ∞ If true exponent = 128 and fraction ≠ 0, then the number is greater than ∞. It is called “not a number” or NaN and may be interpreted as ∞ Biased exponent Fraction (Adapted from V. Agrawal)

18
14-18 Bard, Gerstlauer, Valvano, Yerraballi Negative Infinity in IEEE 754 -1.0 × Smallest negative number in single-precision IEEE 754 standard. Interpreted as - ∞ If true exponent = 128 and fraction ≠ 0, then the number is less than - ∞ It is called “not a number” or NaN and may be interpreted as - ∞ Biased exponent Fraction (Adapted from V. Agrawal)

19
14-19 Bard, Gerstlauer, Valvano, Yerraballi IEEE Representation Values If E=255 and F is nonzero, then V=NaN ("Not a number") If E=255 and F is zero and S is 1, then V=-Infinity If E=255 and F is zero and S is 0, then V=+Infinity If 0

20
14-20 Bard, Gerstlauer, Valvano, Yerraballi Addition and Subtraction 0.Zero check -Change the sign of subtrahend -If either operand is 0, the other is the result 1.Significand alignment: right shift smaller significand until two exponents are identical. 2.Addition: add significands and report exception if overflow occurs. 3.Normalization -Shift significand bits to normalize. -report overflow or underflow if exponent goes out of range. 4.Rounding (Adapted from V. Agrawal)

21
14-21 Bard, Gerstlauer, Valvano, Yerraballi Rounding Adjusting significands before addition will produce results that exceed 24 bit Round toward infinity oselect next largest normalized result Round toward minus infinity oselect next smallest normalized result Round toward zero otruncate result Round to nearest oselect closest normalized result oused by IEEE 754

22
14-22 Bard, Gerstlauer, Valvano, Yerraballi Example Subtraction: Step 0:Floating point numbers to be added ×2 -1 and ×2 -2 Step 1: Significand of lesser exponent is shifted right until exponents match ×2 -2 → ×2 -1 Step 2: Add significands, ( ) Result is ×2 -1 Step 3: Normalize, × 2 -4 No overflow/underflow since 127 ≥ exponent ≥ -126 Step 4: Rounding, no change since the sum fits in 4 bits ×2 -4 = (1+0)/16 = (Adapted from V. Agrawal)

23
14-23 Bard, Gerstlauer, Valvano, Yerraballi FP Multiplication: Basic Idea 1.Separate sign 2.Add exponents 3.Multiply significands 4.Normalize, round, check overflow 5.Replace sign (Adapted from V. Agrawal)

24
14-24 Bard, Gerstlauer, Valvano, Yerraballi FP Division: Basic Idea 1.Separate sign. 2.Check for zeros and infinity. 3.Subtract exponents. 4.Divide significands. 5.Normalize/overflow/underflow. 6.Rounding. 7.Replace sign. (Adapted from V. Agrawal)

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google