Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python math error
#1
Hi all,

I'm new at python but seen a math error. (Python 3.6.4)
Please simply run the code below and see the results.
Also you can try with different numbers...

a=86200
while a>0.0001:
    print(a)
    a/=10

a=0.000862
while a<100000:
    print(a)
    a*=10
I got these results;


Output:
86200 8620.0 862.0 86.2 8.620000000000001 0.8620000000000001 0.08620000000000001 0.008620000000000001 0.0008620000000000001 0.000862 0.008620000000000001 0.08620000000000001 0.8620000000000001 8.620000000000001 86.20000000000002 862.0000000000002 8620.000000000002 86200.00000000001
What can you say me about that error???
Reply
#2
we can tell you that it's not an error
http://floating-point-gui.de/
https://en.wikipedia.org/wiki/Floating-point_arithmetic
https://docs.oracle.com/cd/E19957-01/806...dberg.html
Reply
#3
a simple addition will do, 0.00000000000000001+1, the output is 1.0 .(python 2.7)
swallow osama bin laden
Reply
#4
(Feb-11-2018, 08:52 AM)buran Wrote: we can tell you that it's not an error http://floating-point-gui.de/ https://en.wikipedia.org/wiki/Floating-point_arithmetic https://docs.oracle.com/cd/E19957-01/806...dberg.html

Dear Buran, thank you for your informations...
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to do "fixed size" (wrapping) math in Python? AlexanderWulf 13 1,732 Jul-19-2023, 04:13 PM
Last Post: deanhystad
  Math python question Deonvek 6 1,089 Apr-05-2023, 09:27 PM
Last Post: deanhystad
  math.log versus math.log10 stevendaprano 10 2,313 May-23-2022, 08:59 PM
Last Post: jefsummers
  Math Package in python Uma 1 1,462 Dec-12-2021, 02:01 PM
Last Post: jefsummers
  Why getting ValueError : Math domain error in trig. function, math.asin() ? jahuja73 3 3,705 Feb-24-2021, 05:09 PM
Last Post: bowlofred
  "SyntaxError: invalid syntax" running code in Doing Math With Python b saucerdesigner 2 2,702 Nov-03-2020, 04:23 PM
Last Post: saucerdesigner
  Programming Difficult math in Python Huntern 6 4,688 Oct-17-2019, 06:32 AM
Last Post: Huntern
  python 3 math formulas where to use () Python101 1 2,267 Jun-09-2019, 09:54 PM
Last Post: micseydel
  Python modeling a math solution Masterwoot 1 2,225 Mar-01-2019, 08:50 AM
Last Post: buran
  Math problem python Dhaval 1 2,899 Jun-05-2017, 10:28 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020