Reader small image

You're reading from  Scientific Computing with Python - Second Edition

Product typeBook
Published inJul 2021
Reading LevelIntermediate
PublisherPackt
ISBN-139781838822323
Edition2nd Edition
Languages
Right arrow
Authors (3):
Claus Führer
Claus Führer
author image
Claus Führer

Claus Führer is a professor of scientific computations at Lund University, Sweden. He has an extensive teaching record that includes intensive programming courses in numerical analysis and engineering mathematics across various levels in many different countries and teaching environments. Claus also develops numerical software in research collaboration with industry and received Lund University's Faculty of Engineering Best Teacher Award in 2016.
Read more about Claus Führer

View More author details
Right arrow

2.2.2 Floating-point numbers

If you execute the statement a = 3.0 in Python, you create a floating-point number (Python type: float). These numbers form a finite subset of rational numbers, ℚ.

Alternatively, the constant could have been given in exponent notation as a = 30.0e-1 or simply a = 30.e-1. The symbol e separates the exponent from the mantissa, and the expression reads in mathematical notation as . The name floating-point number refers to the internal representation of these numbers and reflects the floating position of the decimal point when considering numbers over a wide range.

Applying elementary mathematical operations, such as +-*, and /to two floating-point numbers, or to an integer and a floating-point number, returns a floating-point number.

Operations between floating-point numbers rarely return the exact result expected from rational number operations:

0.4 - 0.3 # returns 0.10000000000000003

This fact matters when comparing floating-point numbers:

0.4 - 0.3 == 0.1 # returns False

The reason for this becomes apparent when looking at the internal representation of floating-point numbers; see also Section 15.2.6, Float comparisons.

Previous PageNext Page
You have been reading a chapter from
Scientific Computing with Python - Second Edition
Published in: Jul 2021Publisher: PacktISBN-13: 9781838822323
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (3)

author image
Claus Führer

Claus Führer is a professor of scientific computations at Lund University, Sweden. He has an extensive teaching record that includes intensive programming courses in numerical analysis and engineering mathematics across various levels in many different countries and teaching environments. Claus also develops numerical software in research collaboration with industry and received Lund University's Faculty of Engineering Best Teacher Award in 2016.
Read more about Claus Führer