classification
Title: Error with math.fsum() regarding float-point error
Type: behavior Stage: resolved
Components: Extension Modules Versions: Python 3.8
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Mathias Talbo, mark.dickinson, xtreak
Priority: normal Keywords:

Created on 2020-03-21 08:43 by Mathias Talbo, last changed 2020-03-21 09:03 by serhiy.storchaka. This issue is now closed.

Messages (2)
msg364730 - (view) Author: Mathias Talbo (Mathias Talbo) Date: 2020-03-21 08:43
An issue occurs when running the following code. 

import math
math.fsum([0.1, 0.2]), math.fsum([0.1, 0.7])

This should output 0.3, 0.8 respectively.

Instead, it output 0.30000000000000004, 0.7999999999999999

The very floating-point error it is trying to stop from occurring.

Thank you for your time.
msg364733 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2020-03-21 09:01
This seems to be a similar case of https://docs.python.org/3/tutorial/floatingpoint.html. See also comment https://stackoverflow.com/questions/55534307/calculating-sum-of-float-numbers-using-math-fsum-showing-incorrect-values#comment97782231_55534307 .
History
Date User Action Args
2020-03-21 09:03:29serhiy.storchakasetstatus: open -> closed
resolution: not a bug
stage: resolved
2020-03-21 09:01:45xtreaksetnosy: + mark.dickinson, xtreak
messages: + msg364733
2020-03-21 08:43:29Mathias Talbocreate