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 = 3.14159265... 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 = 9.76 10 14 A small number: 0.0000000000000976 = 9.76 10 -14 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 13.25 × 10 10 becomes 1.325 × 10 11 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 754-1985 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 127 10 or 01111111 2 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 -2 31 2 31 -10 Expressible negative numbers Expressible positive numbers 0-2 -127 2 -127 Positive underflow Negative underflow (2 – 2 -23 )×2 127 - (2 – 2 -23 )×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 ×2 -1 + b 2 ×2 -2 + b 3 ×2 -3 + b 4 ×2 -4 ) × 2 E Example:-1.1100 × 2 -2 (binary)= - (1 + 2 -1 + 2 -2 ) ×2 -2 = - (1 + 0.5 + 0.25)/4 = - 1.75/4 = - 0.4375 (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 100 10 Step 1 – convert to binary - 0110 0100 In a binary representation form of 1.xxx have 0110 0100 = 1.100100 x 2 6

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

15
14-15 Bard, Gerstlauer, Valvano, Yerraballi Positive Zero in IEEE 754 + 1.0 × 2 -127 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. 0 00000000 00000000000000000000000 Biased exponent Fraction (Adapted from V. Agrawal)

16
14-16 Bard, Gerstlauer, Valvano, Yerraballi Negative Zero in IEEE 754 - 1.0 × 2 -127 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 0. 1 00000000 00000000000000000000000 Biased exponent Fraction (Adapted from V. Agrawal)

17
14-17 Bard, Gerstlauer, Valvano, Yerraballi Positive Infinity in IEEE 754 + 1.0 × 2 128 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 ∞. 0 11111111 00000000000000000000000 Biased exponent Fraction (Adapted from V. Agrawal)

18
14-18 Bard, Gerstlauer, Valvano, Yerraballi Negative Infinity in IEEE 754 -1.0 × 2 128 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 - ∞. 1 11111111 00000000000000000000000 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: 0.5 10 - 0.4375 10 Step 0:Floating point numbers to be added 1.000 2 ×2 -1 and -1.110 2 ×2 -2 Step 1: Significand of lesser exponent is shifted right until exponents match -1.110 2 ×2 -2 → - 0.111 2 ×2 -1 Step 2: Add significands, 1.000 2 + (- 0.111 2 ) Result is 0.001 2 ×2 -1 Step 3: Normalize, 1.000 2 × 2 -4 No overflow/underflow since 127 ≥ exponent ≥ -126 Step 4: Rounding, no change since the sum fits in 4 bits. 1.000 2 ×2 -4 = (1+0)/16 = 0.0625 10 (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

OK

4. Floating Point Numbers. Exponential Notation The representations differ in that the decimal place – the “point” -- “floats” to the left or right (with.

4. Floating Point Numbers. Exponential Notation The representations differ in that the decimal place – the “point” -- “floats” to the left or right (with.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on cloud computing free download Ppt on abo blood groupings Ppt on inhabiting other planets in the solar Ppt on beer lambert law definition Ppt on global warming and greenhouse effect Ppt on object recognition in dip Ppt on book of revelation Ppt on resources and development class 10 cbse results Ppt on cartesian product of sets Ppt on magnetohydrodynamic power generation