SlideShare a Scribd company logo
1 of 25
Chapter 6 Floating Point
Outline
1. Floating Point Representation
2. Floating Point Arithmetic
3. The Numeric Coprocessor
1. Floating Point Representation
• Non-integral binary numbers
– 0.123 = 1 × 10−1 + 2 × 10−2 + 3 × 10−3
– 0.1012 = 1 × 2−1 + 0 × 2−2 + 1 × 2−3 = 0.625
– 110.0112 = 4 + 2 + 0.25 + 0.125 = 6.375
10进制  2进制 (整数)
139
2 (余1
69
2 (余1
34
2 (余0
17
2 (余1
8
2 (余0
4
2 (余0
2
2 (余0
1
10001011
(139)10=(10001011)2
除
余
法
10进制  2进制 (小数)
(0.6875)10 = (0.1011)2
0.6875
 2
1.3750 … 整数部分为 1
0.375
 2
0.750
 2
… 整数部分为 0
1.500 … 整数部分为 1
0.500
 2
1.0 … 整数部分为 1
小数部分为 0
Converting 0.85 to binary
0.85 × 2 = 1.7
0.7 × 2 = 1.4
0.4 × 2 = 0.8
0.8 × 2 = 1.6
0.6 × 2 = 1.2
0.2 × 2 = 0.4
0.4 × 2 = 0.8
0.8 × 2 = 1.6
A consistent format
e.g., 23.85 or 10111.11011001100110 . . .2
would be stored as:
1.011111011001100110 . . . × 2100
A normalized floating point number
has the form:
1.ssssssssssssssss × 2eeeeeee
where 1.sssssssssssss is the significand and eeeeeeee
is the exponent.
IEEE floating point representation
• The IEEE (Institute of Electrical and Electronic
Engineers) is an international organization that has
designed specific binary formats for storing floating
point numbers.
• The IEEE defines two different formats with different
precisions: single and double precision. Single precision
is used by float variables in C and double precision is
used by double variables.
• Intel’s math coprocessor also uses a third, higher
precision called extended precision. In fact, all data in
the coprocessor itself is in this precision. When it is
stored in memory from the coprocessor it is converted
to either single or double precision automatically.
IEEE single precision
• The binary exponent is not stored directly. Instead, the sum of
the exponent and 7F is stored from bit 23 to 30. This biased
exponent is always non-negative.
• The fraction part assumes a normalized significand (in the
form 1.sssssssss).Since the first bit is always an one, the leading
one is not stored! This allows the storage of an additional bit at
the end and so increases the precision slightly. This idea is
know as the hidden one representation.
mantissa
How would 23.85 be stored?
• First, it is positive so the sign bit is 0.
• Next, the true exponent is 4, so the biased exponent is
7F+4 = 8316.
• Finally, the fraction is 01111101100110011001100
(remember the leading one is hidden).
• -23.85 be represented? Just change the sign bit: C1 BE
CC CD. Do not take the two’s complement!
Special meanings for IEEE floats.
• An infinity is produced by an overflow or by division by zero.
An undefined result is produced by an invalid operation such
as trying to find the square root of a negative number, adding
two infinities, etc.
• Normalized single precision numbers can range in magnitude
from 1.0× 2−126 ( ≈1.1755 × 10−35) to 1.11111 . . . × 2127 (≈
3.4028 × 1035).
Denormalized numbers
• Denormalized numbers can be used to represent
numbers with magnitudes too small to normalize
(i.e. below 1.0×2−126).
• E.g., 1.0012×2−129 ( ≈1.6530×10−39). in the
unnormalized form: 0.010012 × 2−127.
• To store this number, the biased exponent is set to
0 and the fraction is the complete significand of
the number written as a product with 2−127
IEEE double precision
• IEEE double precision uses 64 bits to represent
numbers and is usually accurate to about 15
significant decimal digits.
• 用 11 位表示指数,52 位表示尾数。
• The double precision has the same special values
as single precision.
mantissa
2. Floating Point Arithmetic
• Floating point arithmetic on a computer is
different than in continuous mathematics.
– In mathematics, all numbers can be
considered exact. on a computer many
numbers can not be represented exactly with a
finite number of bits.
– All calculations are performed with limited
precision.
Addition
• To add two floating point numbers, the exponents
must be equal. If they are not already equal, then
they must be made equal by shifting the
significand of the number with the smaller
exponent.
• E.g., 10.375 + 6.34375 = 16.71875
1.0100110 × 23
+ 1.1001011 × 22
-----------------------------------------
16.75
It is important to realize that floating point arithmetic on a
computer (or calculator) is always an approximation.
Subtraction
Multiplication and division
• For multiplication, the significands are multiplied and
the exponents are added. Consider 10.375 × 2.5 =
25.9375:
• Division is more complicated, but has similar
problems with round off errors.
浮点数比较
• The main point of this section is that floating point
calculations are not exact. The programmer needs
to be aware of this.
• if ( f (x) == 0.0 ) error
• if ( fabs( f (x)) < EPS ) EPS is a macro
• To compare a floating point value (say x) to
another (y) use:
– if ( fabs(x − y)/fabs(y) < EPS )
epsilon
3. The Numeric Coprocessor
• Hardware
• Instructions
• Examples
• Quadratic formula
• Reading array from file
• Finding primes
Hardware
• A math coprocessor has machine instructions that
perform many floating point operations much
faster than using a software procedure.
• Since the Pentium, all generations of 80x86
processors have a builtin math coprocessor.
• The numeric coprocessor has eight floating point
registers. Each register holds 80-bits of data.
• The registers are named ST0, ST1, ST2, . . . ST7,
which are organized as a stack.
• There is also a status register in the numeric
coprocessor. It has several flags. Only the 4 flags
used for comparisons will be covered: C0, C1, C2
and C3.
Instructions, at Page 123
• Loading and storing
• Addition and subtraction
– Array sum example
• Multiplication and division
• Comparisons
Quadratic formula
Reading array form file
• readt.c
• read.asm
Finding primes
• fprime.c
• prime2.asm
Summary
1. Floating Point Representation
2. Floating Point Arithmetic
3. The Numeric Coprocessor

More Related Content

Similar to number system: Floating Point representation.ppt

B.sc cs-ii-u-1.8 digital logic circuits, digital component floting and fixed ...
B.sc cs-ii-u-1.8 digital logic circuits, digital component floting and fixed ...B.sc cs-ii-u-1.8 digital logic circuits, digital component floting and fixed ...
B.sc cs-ii-u-1.8 digital logic circuits, digital component floting and fixed ...Rai University
 
Beyond Floating Point – Next Generation Computer Arithmetic
Beyond Floating Point – Next Generation Computer ArithmeticBeyond Floating Point – Next Generation Computer Arithmetic
Beyond Floating Point – Next Generation Computer Arithmeticinside-BigData.com
 
09 arithmetic
09 arithmetic09 arithmetic
09 arithmeticargiaggi
 
Arithmetic of Computers
Arithmetic of Computers Arithmetic of Computers
Arithmetic of Computers Dhamodhar M
 
IEEE-754 standard format to handle Floating-Point calculations in RISC-V CPUs...
IEEE-754 standard format to handle Floating-Point calculations in RISC-V CPUs...IEEE-754 standard format to handle Floating-Point calculations in RISC-V CPUs...
IEEE-754 standard format to handle Floating-Point calculations in RISC-V CPUs...zeeshanshanzy009
 
Module 1 number systems and code1
Module 1  number systems and code1Module 1  number systems and code1
Module 1 number systems and code1Deepak John
 
1.Digital Electronics overview & Number Systems.pptx
1.Digital Electronics overview & Number Systems.pptx1.Digital Electronics overview & Number Systems.pptx
1.Digital Electronics overview & Number Systems.pptxLibanMohamed26
 
Floating point representation and arithmetic
Floating point representation and arithmeticFloating point representation and arithmetic
Floating point representation and arithmeticAvirajKaushik
 
data representation
 data representation data representation
data representationHaroon_007
 
digital-electronics.pptx
digital-electronics.pptxdigital-electronics.pptx
digital-electronics.pptxsulekhasaxena2
 
DATA REPRESENTATION.pptx
DATA REPRESENTATION.pptxDATA REPRESENTATION.pptx
DATA REPRESENTATION.pptxMamataAnilgod
 

Similar to number system: Floating Point representation.ppt (20)

COA unit 2.pptx
COA unit 2.pptxCOA unit 2.pptx
COA unit 2.pptx
 
B.sc cs-ii-u-1.8 digital logic circuits, digital component floting and fixed ...
B.sc cs-ii-u-1.8 digital logic circuits, digital component floting and fixed ...B.sc cs-ii-u-1.8 digital logic circuits, digital component floting and fixed ...
B.sc cs-ii-u-1.8 digital logic circuits, digital component floting and fixed ...
 
09 arithmetic
09 arithmetic09 arithmetic
09 arithmetic
 
Beyond Floating Point – Next Generation Computer Arithmetic
Beyond Floating Point – Next Generation Computer ArithmeticBeyond Floating Point – Next Generation Computer Arithmetic
Beyond Floating Point – Next Generation Computer Arithmetic
 
L 2.10
L 2.10L 2.10
L 2.10
 
09 Arithmetic
09  Arithmetic09  Arithmetic
09 Arithmetic
 
09 arithmetic
09 arithmetic09 arithmetic
09 arithmetic
 
Arithmetic of Computers
Arithmetic of Computers Arithmetic of Computers
Arithmetic of Computers
 
09 arithmetic
09 arithmetic09 arithmetic
09 arithmetic
 
09 arithmetic 2
09 arithmetic 209 arithmetic 2
09 arithmetic 2
 
IEEE-754 standard format to handle Floating-Point calculations in RISC-V CPUs...
IEEE-754 standard format to handle Floating-Point calculations in RISC-V CPUs...IEEE-754 standard format to handle Floating-Point calculations in RISC-V CPUs...
IEEE-754 standard format to handle Floating-Point calculations in RISC-V CPUs...
 
06 floating point
06 floating point06 floating point
06 floating point
 
Module 1 number systems and code1
Module 1  number systems and code1Module 1  number systems and code1
Module 1 number systems and code1
 
1.Digital Electronics overview & Number Systems.pptx
1.Digital Electronics overview & Number Systems.pptx1.Digital Electronics overview & Number Systems.pptx
1.Digital Electronics overview & Number Systems.pptx
 
Floating point representation and arithmetic
Floating point representation and arithmeticFloating point representation and arithmetic
Floating point representation and arithmetic
 
data representation
 data representation data representation
data representation
 
digital-electronics.pptx
digital-electronics.pptxdigital-electronics.pptx
digital-electronics.pptx
 
Number system
Number systemNumber system
Number system
 
Digital Electronics Notes.pdf
Digital Electronics Notes.pdfDigital Electronics Notes.pdf
Digital Electronics Notes.pdf
 
DATA REPRESENTATION.pptx
DATA REPRESENTATION.pptxDATA REPRESENTATION.pptx
DATA REPRESENTATION.pptx
 

Recently uploaded

CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 

Recently uploaded (20)

CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 

number system: Floating Point representation.ppt

  • 2. Outline 1. Floating Point Representation 2. Floating Point Arithmetic 3. The Numeric Coprocessor
  • 3. 1. Floating Point Representation • Non-integral binary numbers – 0.123 = 1 × 10−1 + 2 × 10−2 + 3 × 10−3 – 0.1012 = 1 × 2−1 + 0 × 2−2 + 1 × 2−3 = 0.625 – 110.0112 = 4 + 2 + 0.25 + 0.125 = 6.375
  • 4. 10进制  2进制 (整数) 139 2 (余1 69 2 (余1 34 2 (余0 17 2 (余1 8 2 (余0 4 2 (余0 2 2 (余0 1 10001011 (139)10=(10001011)2 除 余 法
  • 5. 10进制  2进制 (小数) (0.6875)10 = (0.1011)2 0.6875  2 1.3750 … 整数部分为 1 0.375  2 0.750  2 … 整数部分为 0 1.500 … 整数部分为 1 0.500  2 1.0 … 整数部分为 1 小数部分为 0
  • 6. Converting 0.85 to binary 0.85 × 2 = 1.7 0.7 × 2 = 1.4 0.4 × 2 = 0.8 0.8 × 2 = 1.6 0.6 × 2 = 1.2 0.2 × 2 = 0.4 0.4 × 2 = 0.8 0.8 × 2 = 1.6
  • 7. A consistent format e.g., 23.85 or 10111.11011001100110 . . .2 would be stored as: 1.011111011001100110 . . . × 2100 A normalized floating point number has the form: 1.ssssssssssssssss × 2eeeeeee where 1.sssssssssssss is the significand and eeeeeeee is the exponent.
  • 8. IEEE floating point representation • The IEEE (Institute of Electrical and Electronic Engineers) is an international organization that has designed specific binary formats for storing floating point numbers. • The IEEE defines two different formats with different precisions: single and double precision. Single precision is used by float variables in C and double precision is used by double variables. • Intel’s math coprocessor also uses a third, higher precision called extended precision. In fact, all data in the coprocessor itself is in this precision. When it is stored in memory from the coprocessor it is converted to either single or double precision automatically.
  • 9. IEEE single precision • The binary exponent is not stored directly. Instead, the sum of the exponent and 7F is stored from bit 23 to 30. This biased exponent is always non-negative. • The fraction part assumes a normalized significand (in the form 1.sssssssss).Since the first bit is always an one, the leading one is not stored! This allows the storage of an additional bit at the end and so increases the precision slightly. This idea is know as the hidden one representation. mantissa
  • 10. How would 23.85 be stored? • First, it is positive so the sign bit is 0. • Next, the true exponent is 4, so the biased exponent is 7F+4 = 8316. • Finally, the fraction is 01111101100110011001100 (remember the leading one is hidden). • -23.85 be represented? Just change the sign bit: C1 BE CC CD. Do not take the two’s complement!
  • 11. Special meanings for IEEE floats. • An infinity is produced by an overflow or by division by zero. An undefined result is produced by an invalid operation such as trying to find the square root of a negative number, adding two infinities, etc. • Normalized single precision numbers can range in magnitude from 1.0× 2−126 ( ≈1.1755 × 10−35) to 1.11111 . . . × 2127 (≈ 3.4028 × 1035).
  • 12. Denormalized numbers • Denormalized numbers can be used to represent numbers with magnitudes too small to normalize (i.e. below 1.0×2−126). • E.g., 1.0012×2−129 ( ≈1.6530×10−39). in the unnormalized form: 0.010012 × 2−127. • To store this number, the biased exponent is set to 0 and the fraction is the complete significand of the number written as a product with 2−127
  • 13. IEEE double precision • IEEE double precision uses 64 bits to represent numbers and is usually accurate to about 15 significant decimal digits. • 用 11 位表示指数,52 位表示尾数。 • The double precision has the same special values as single precision. mantissa
  • 14. 2. Floating Point Arithmetic • Floating point arithmetic on a computer is different than in continuous mathematics. – In mathematics, all numbers can be considered exact. on a computer many numbers can not be represented exactly with a finite number of bits. – All calculations are performed with limited precision.
  • 15. Addition • To add two floating point numbers, the exponents must be equal. If they are not already equal, then they must be made equal by shifting the significand of the number with the smaller exponent. • E.g., 10.375 + 6.34375 = 16.71875 1.0100110 × 23 + 1.1001011 × 22 ----------------------------------------- 16.75 It is important to realize that floating point arithmetic on a computer (or calculator) is always an approximation.
  • 17. Multiplication and division • For multiplication, the significands are multiplied and the exponents are added. Consider 10.375 × 2.5 = 25.9375: • Division is more complicated, but has similar problems with round off errors.
  • 18. 浮点数比较 • The main point of this section is that floating point calculations are not exact. The programmer needs to be aware of this. • if ( f (x) == 0.0 ) error • if ( fabs( f (x)) < EPS ) EPS is a macro • To compare a floating point value (say x) to another (y) use: – if ( fabs(x − y)/fabs(y) < EPS ) epsilon
  • 19. 3. The Numeric Coprocessor • Hardware • Instructions • Examples • Quadratic formula • Reading array from file • Finding primes
  • 20. Hardware • A math coprocessor has machine instructions that perform many floating point operations much faster than using a software procedure. • Since the Pentium, all generations of 80x86 processors have a builtin math coprocessor. • The numeric coprocessor has eight floating point registers. Each register holds 80-bits of data. • The registers are named ST0, ST1, ST2, . . . ST7, which are organized as a stack. • There is also a status register in the numeric coprocessor. It has several flags. Only the 4 flags used for comparisons will be covered: C0, C1, C2 and C3.
  • 21. Instructions, at Page 123 • Loading and storing • Addition and subtraction – Array sum example • Multiplication and division • Comparisons
  • 23. Reading array form file • readt.c • read.asm
  • 25. Summary 1. Floating Point Representation 2. Floating Point Arithmetic 3. The Numeric Coprocessor