CST8118 Computer Essentials: IEEE 754 Single Precision Format PDF

Summary

This document discusses the IEEE 754 single precision format, used by computers to represent floating-point numbers. It explores concepts like accuracy and precision along with conversion examples. The document may be part of a larger course related to computer science or computer engineering.

Full Transcript

CST8118 Computer Essentials IEEE 754 Single Precision Format Week 5: IEEE 754 Single Precision Format Introduction to IEEE-754 Terms to know - Range Terms to know - Accuracy Terms to know - Precision The IEEE-754 Single Precision Standard: How computers s...

CST8118 Computer Essentials IEEE 754 Single Precision Format Week 5: IEEE 754 Single Precision Format Introduction to IEEE-754 Terms to know - Range Terms to know - Accuracy Terms to know - Precision The IEEE-754 Single Precision Standard: How computers store floating point numbers Some terms to know Process to convert from Base-10 to Base-2 floating point. Example 1 Example 2 Example 3 2 Introduction to IEEE-754 IEEE 754-2008 the 32-bit base 2 format is officially referred to as Binary32. It was called single in IEEE 754-1985. In older computers, other floating-point formats of 4 bytes were used. One of the first programming languages to provide single- and double-precision floating-point data types was Fortran. Before the widespread adoption of IEEE 754-1985, the representation and properties of the double float data type depended on the computer manufacturer and computer model. Single precision is known as float in C, C++, C#, and Java. 3 Terms to know - Range Range is very straightforward, it represents the interval from the smallest value to the largest value in that same format. Floating point range : Approximately 1.2 × 10^-38 to 3.4 × 10^38 Even with this large range, there are infinitely many numbers that do not exist within the range specified. However there will always be a number in the range that is close to number you want 4 Terms to know - Accuracy Accuracy refers to how close a number is to its’ true value. Example we can’t represent 0.1 in floating point but we can find a number in a range that is relatively close or reasonably accurate to 0.1 Example: How close you are to the center of a target, e.g. archery, bowling, shooting range. Hitting the bullseye would be an accurate shot. 5 Terms to know - Precision Precision refers to how much information we have about a value and the amount of information used to represent a value. Example: 1.666 is a number with 4 decimal digits of precision. 1.6660 is the same exact number but with 5 decimal digits of precision. This is not more accurate than 1.666 Example: When you shoot at a target, if you always hit the same spot you have precision. E.g. archery, bowling, shooting range. You can have high precision, and low accuracy (or vice-versa) precision and accuracy are not the same thing. See: Practices of Science: Precision vs. Accuracy. manoa.hawaii.edu. https://manoa.hawaii.edu/exploringourfluidearth/physical/world-ocean/map-distortion/practices-science-pre cision-vs-accuracy (Accessed Jan 30, 2023) 6 Terms to know - Precision Higher precision often allows a value to be more accurate but this is not always the case. Example: Declare a value of 1 as an integer, a floating point and a double Each number is equally (exactly) accurate. Each time we store a value of 1 the process is also precise. 7 Terms to know - Precision Higher precision often allows a value to be more accurate but this is not always the case. Example: Store a value of 0.1 in Java. E.g. float number = 0.1F; In memory the value is actually: 0.100000001490116119384765625 This is not perfectly accurate, i.e. not 0.1 exactly, however it is precise in that when you attempt to store 0.1, you will always get 0.100000001490116119384765625 instead. Aside: Java API libraries will output 0.1 rather than the actual stored value. See: B. Varhegyi, S. Savaşçı, assylias, J. Skeet, S. C. Why 0.1 represented in float correctly? (I know why not in result of 2.0-1.9). stackoverflow.com. https://stackoverflow.com/questions/12128829/why-0-1-represented-in-float-correctly-i-know-why-not-in-res ult-of-2-0-1-9 (Accessed Jan 30, 2023) 8 Terms to know - Precision Another example: mathematical PI(): pi1 = 3.14159 and pi2 = 3.14 pi1 is the most accurate for any number with 6 digits of precision pi2 is the most accurate for any number with 3 digits of precision A value of 3.12312312312312 is more precise than either pi1 or pi2, but it is less accurate. Adding even more digits of precision will not make 3.12(etc.) more accurate. See: Precision. byjus.com. https://byjus.com/maths/precision/ (Accessed Jan 30, 2023) NASA/JPL Edu. How Many Decimals of Pi Do We Really Need? https://www.jpl.nasa.gov/edu/news/2016/3/16/how-many-decimals-of-pi-do-we-really-need/ (Accessed Jan 30, 2023) 9 The IEEE-754 Single Precision Standard: How computers store floating point numbers The IEEE-754 single precision floating point standard uses an 8-bit exponent and a 23-bit significand. The IEEE-754 double precision standard uses an 11-bit exponent and a 52-bit significand. We can represent the IEEE-754 single precision standard as a horizontal bar, separated into sections from left to right: Sign Bit (1 bit) Exponent (8 bits) Mantissa (23 bits) 10 The IEEE-754 Single Precision Standard: How computers store floating point numbers Floating point numbers are stored on byte boundaries Legend: S – Sign bit E – Exponent (8 bits) M-Mantissa (23 bits) Example: 4 bytes addresses, Address+0 to Address+3, each with 8 bits Address+0 has: SEEEEEEE Address+1 has: EMMMMMMM Address+2 has: MMMMMMMM Address+3 has: MMMMMMMM 11 The IEEE-754 Single Precision Standard: How computers store floating point numbers This gives from 6 to 9 significant decimal digits precision If a decimal string with at most 6 significant decimals (6 to 9 significant decimals inclusive) is converted to IEEE 754 single precision and then converted back to the same number of significant decimal, then the final string should match the original. 12 Some terms to know Sign Bit: Indicates if the number is positive or negative If the sign bit is 0 then the number is positive If the sign bit is 1 then the number is negative K stands for constant, it is used to calculate the exponent K = 127 Hidden “1” used to normalize a number – it is assumed to be there but not actually stored in memory See: Your textbook page 95 Floating point / Lesson Four. wikiversity.org. https://en.wikiversity.org/wiki/Floating_point/Lesson_Four (Accessed Jan 30, 2023) 13 How to convert a decimal number to IEEE 754 Single precision format Step 1. Convert the Decimal number to binary. Step 2. Normalize the Binary fractional number Move the decimal place so that there is always a 1 to the left of the decimal Step 3. Convert the exponent to 8 bit excess 127 notation K+n = 127 + n = Exponent Convert to binary Step 4. Convert the significant/mantissa to “hidden bit format” remove the 1 from the left of the decimal. 14 How to convert a decimal number to IEEE 754 Single precision format (Continued) Sign bit: 0 for positive numbers, 1 for negative numbers Step 5: List the three parts in order. Sign bit: 1 bit Exponent: 8 bits Mantissa: 23 bits Step 6: Sign bit Exponent Mantissa Step 7 Convert the final answer to Hex to make it easy to read 15 Example #1 Convert 8.7510 to IEEE 754 Single precision format Step 1. Convert 8.75 to binary 8.75 = 1000.112 Step 2. Normalize the Binary fractional number 1000.112 * 20 Move the decimal place so that there is a 1 to the left of the decimal 1.00011 * 23 16 Example #1 Continued Step 3. Convert the exponent to 8 bit excess 127 notation The number of places we moved the decimal + 127 3+127 = 130 convert to binary 1000 0010 Step 4. Convert the significant/mantissa to “hidden bit format” remove the 1 from the left of the decimal. 1.00011 becomes 00011 Determine the sign Bit Since the number 8.7510 is positive the sign bit is 0 17 Example #1 continued Step 5 Sign bit: 0 Exponent: 1000 0010 Mantissa: 00011 Step 6: 0100 0001 0000 1100 0000 0000 0000 00002 Step 7 Convert the final answer to Hex to make it easy to read 410C000016 18 Example #2 Convert -0.510 to IEEE 754 Single precision format Step 1. Convert 0.5 to binary: 0.510 = 0.12 Step 2. Normalize the Binary fractional number 0.12 * 20 Move the decimal place so that there is a 1 to the left of the decimal 1.0 * 2-1 (we had to move right in this case, hence 2 raised to -1) 19 Example #2 Continued Step 3. Convert the exponent to 8 bit excess 127 notation The number of places we moved the decimal + K -1 + 127 = 126 convert to binary 0111 11102 Step 4. Convert the significant/mantissa to “hidden bit format” remove the 1 from the left of the decimal. 1.0 becomes 0 Determine the sign Bit Since the number -0.510 is negative the sign bit is 1 20 Example #2 Continued Step 5 Sign bit: 1 Exponent: 0111 1110 = 126 Mantissa: 0 Step 6: 1011 1111 0000 0000 0000 0000 0000 0000 Step 7: Convert the final answer to Hex to make it easy to read BF00000016 21 Example #3 Convert -1.062510 to IEEE 754 Single precision format Step 1. Convert -1.0625 to binary: -1.062510 = 1.00012 Step 2. Normalize the Binary fractional number 1.00012 * 20 There is no need to move the decimal place in this example 1.0001 * 20 22 Example #3 Step 3. Convert the exponent to 8 bit excess 127 notation K + 0 = 127 + 0 = 127 convert to binary 0111 11112 Step 4. Convert the significant/mantissa to “hidden bit format” remove the 1 from the left of the decimal. 1.0001 becomes 0001 Determine the sign Bit Since the number -1.062510 is negative the sign bit is 1 23 Example #3 Continued Step 5: Since the number we are converting is negative the sign bit is: 1 Sign bit: 1 Exponent: 0111 1111 = 127 Mantissa: 0001 Step 6 : 1011 1111 1000 1000 0000 0000 0000 00002 Step 7 Convert the final answer to Hex to make it easy to read BF88000016 24 Conclusion In this lesson, you learned… Introduction to IEEE-754 Terms to know - Range Terms to know - Accuracy Terms to know - Precision The IEEE-754 Single Precision Standard: How computers store floating point numbers Some terms to know Process to convert from Base-10 to Base-2 floating point. Example 1 Example 2 Example 3 25 Sources Cited Single-precision floating-point format. wikipedia.org. https://en.wikipedia.org/wiki/Single-precision_floating-point_format (Accessed Jan 30, 2023) Type float. learn.microsoft.com. https://learn.microsoft.com/en-us/cpp/c-language/type-float?view=msvc-170 (Accessed Jan 30, 2023) User's Guides for Keil C51 Development Tools. developer.arm.com. https://developer.arm.com/documentation/101655/0961/Cx51-User-s-Guide/Advanced-Programming/ Data-Storage-Formats/Floating-point-Numbers (Accessed Jan 30, 2023) Single-precision floating-point format. wikipedia.org. https://en.wikipedia.org/wiki/Single-precision_floating-point_format (Accessed Jan 30, 2023) W. Kahan. Lecture Notes on the Status of IEEE Standard 754 for Binary Floating-Point Arithmetic. people.eecs.berkeley.edu. https://people.eecs.berkeley.edu/~wkahan/ieee754status/IEEE754.PDF (Accessed Jan 30, 2023) 26 Additional Learning Resources / Practice Learning Resource Convert 8.75 to 32 Bit Single Precision IEEE 754 Binary Floating Point Standard, From a Base 10 Decimal Number. binary-system.base-conversion.ro https://binary-system.base-conversion.ro/convert-real-numbers-from-decimal-system-to-32b it-single-precision-IEEE754-binary-floating-point.php (Accessed Jan 30, 2023) – Use form at the bottom of the web page to see examples for different numbers. – You may be expected to perform this type of calculation long-hand on closed book tests. – So, practice, practice, practice Checking Answers Tools & Thoughts IEEE-754 Floating Point Converter. H-Schmidt.net. https://www.h-schmidt.net/FloatConverter/IEEE754.html (Accessed Jan 30, 2023) 27 Recommended Reading (Optional) Practices of Science: Precision vs. Accuracy. manoa.hawaii.edu. https://manoa.hawaii.edu/exploringourfluidearth/physical/world-ocean/map-distortion/practices-scie nce-precision-vs-accuracy (Accessed Jan 30, 2023) Precision. byjus.com. https://byjus.com/maths/precision/ (Accessed Jan 30, 2023) NASA/JPL Edu. How Many Decimals of Pi Do We Really Need? https://www.jpl.nasa.gov/edu/news/2016/3/16/how-many-decimals-of-pi-do-we-really-need/ (Accessed Jan 30, 2023) Floating point / Lesson Four. wikiversity.org. https://en.wikiversity.org/wiki/Floating_point/Lesson_Four (Accessed Jan 30, 2023) S. Hollasch. IEEE Standard 754 Floating Point Numbers. steve.hollasch.net. https://steve.hollasch.net/cgindex/coding/ieeefloat.html (Accessed Jan 30, 2023) IEEE Standard 754 Floating Point Numbers. geeksforgeeks.org. https://www.geeksforgeeks.org/ieee-standard-754-floating-point-numbers/ (Accessed Jan 30, 2023) 28 Recommended Video (Optional) SuperWespa. How to convert Decimal number to Floating point number [IEEE 754] youtube.com. https://www.youtube.com/watch?v=MIrQtuoT5Ak (Accessed Jan 30, 2023) 29

Use Quizgecko on...
Browser
Browser