Floating-Point Operations Ali Taheri Sharif University of - - PowerPoint PPT Presentation

floating point operations
SMART_READER_LITE
LIVE PREVIEW

Floating-Point Operations Ali Taheri Sharif University of - - PowerPoint PPT Presentation

Fu Fundamentals of Pr Programming (Py Python) Floating-Point Operations Ali Taheri Sharif University of Technology Spring 2019 Outline 1. Fixed-Point Representation 2. Floating-Point Representation 3. Arithmetic Errors 4. The math


slide-1
SLIDE 1

Fu Fundamentals of Pr Programming (Py Python)

Floating-Point Operations

Ali Taheri Sharif University of Technology

Spring 2019

slide-2
SLIDE 2

Outline

  • 1. Fixed-Point Representation
  • 2. Floating-Point Representation
  • 3. Arithmetic Errors
  • 4. The math Module

2

ALI TAHERI - FUNDAMENTALS OF PROGRAMMING [PYTHON] Spring 2019

slide-3
SLIDE 3

Fixed-Point

The number of bits before and after the decimal point is fixed

  • Example: 98.75

3

ALI TAHERI - FUNDAMENTALS OF PROGRAMMING [PYTHON] Spring 2019

slide-4
SLIDE 4

Floating-Point

Supports a trade-off between range and precision

IEEE 754 Standard:

4

ALI TAHERI - FUNDAMENTALS OF PROGRAMMING [PYTHON] Spring 2019

𝒕𝒋𝒉𝒐𝒋𝒈𝒋𝒅𝒃𝒐𝒆 ∗ 𝒄𝒃𝒕𝒇𝒇𝒚𝒒𝒑𝒐𝒇𝒐𝒖

slide-5
SLIDE 5

Arithmetic Errors

When dealing with floating-point numbers, the result of calculation may not be necessarily correct: You should be careful when doing comparisons:

5

ALI TAHERI - FUNDAMENTALS OF PROGRAMMING [PYTHON] Spring 2019

0.1 + 0.1 + 0.1 == 0.3 7/5 - 1 == 2/5 1 - 1/3 == 2/3

abs(a-b) < 1e-4

slide-6
SLIDE 6

The math module

Implements many of the IEEE functions for complex mathematical operations using floating point values, including logarithms and trigonometric operations. The import keyword enables us to include additional modules into our program

6

ALI TAHERI - FUNDAMENTALS OF PROGRAMMING [PYTHON] Spring 2019

import math