Re: Floating point problem

2020-06-23 Thread Tony Flury via Python-list
On 18/04/2020 15:29, Grant Edwards wrote: On 2020-04-18, Souvik Dutta wrote: I literally tried it!!! And it did not stop because I did not get any 1.0 rather I got 0.999 But why does this happen. This is a simple math which according to normal human logic should give perfect numbers

Re: Floating point problem

2020-04-21 Thread Richard Damon
On 4/21/20 9:43 AM, Chris Angelico wrote: > Right. Now try diagnosing weird bugs in floating-point calculations, > and you aren't sure if it's because sometimes you have 53 bits of > mantissa and sometimes only 52. > And sometimes only 1. The smallest positive floating point number has only 1

Re: Floating point problem

2020-04-21 Thread Chris Angelico
On Tue, Apr 21, 2020 at 11:31 PM Pieter van Oostrum wrote: > > Chris Angelico writes: > > > On Tue, Apr 21, 2020 at 6:07 AM Schachner, Joseph > > wrote: > >> > >> 16 base 10 digits / log base10( 2) = 53.1508495182 bits. Obviously, > >> fractional bits don't exist, so 53 bits. If you note that

Re: Floating point problem

2020-04-21 Thread Pieter van Oostrum
Chris Angelico writes: > On Tue, Apr 21, 2020 at 6:07 AM Schachner, Joseph > wrote: >> >> 16 base 10 digits / log base10( 2) = 53.1508495182 bits. Obviously, >> fractional bits don't exist, so 53 bits. If you note that the first >> non-zero digit as 4, and the first digit after the 15 zeroes

Re: Floating point problem

2020-04-20 Thread Richard Damon
On 4/20/20 4:19 PM, Chris Angelico wrote: > On Tue, Apr 21, 2020 at 6:07 AM Schachner, Joseph > wrote: >> 16 base 10 digits / log base10( 2) = 53.1508495182 bits. Obviously, >> fractional bits don't exist, so 53 bits. If you note that the first non-zero >> digit as 4, and the first digit

Re: Floating point problem

2020-04-20 Thread Chris Angelico
On Tue, Apr 21, 2020 at 6:07 AM Schachner, Joseph wrote: > > 16 base 10 digits / log base10( 2) = 53.1508495182 bits. Obviously, > fractional bits don't exist, so 53 bits. If you note that the first non-zero > digit as 4, and the first digit after the 15 zeroes was 2, then you got an > extra

RE: Floating point problem

2020-04-20 Thread Schachner, Joseph
. -Original Message- From: Pieter van Oostrum Sent: Sunday, April 19, 2020 7:49 AM To: python-list@python.org Subject: Re: Floating point problem "R.Wieser" writes: > Souvik, > >> I have one question here. On using print(f"{c:.32f}") where c= 2/5 >> i

Re: Floating point problem

2020-04-19 Thread Pieter van Oostrum
"R.Wieser" writes: > Souvik, > >> I have one question here. On using print(f"{c:.32f}") where c= 2/5 >> instead of getting 32 zeroes I got some random numbers. The exact >> thing is 0.40002220446049250313 Why do I get >> this and not 32 zeroes? > > Simple answer ? The conversion

Re: Floating point problem

2020-04-18 Thread Chris Angelico
On Sun, Apr 19, 2020 at 4:26 AM Grant Edwards wrote: > > On 2020-04-18, Souvik Dutta wrote: > > I literally tried it!!! And it did not stop because I did not get any 1.0 > > rather I got 0.999 But why does this happen. This is a simple math > > which according to normal human logic

Re: Floating point problem

2020-04-18 Thread Grant Edwards
On 2020-04-18, Dennis Lee Bieber wrote: > At the very least, one was taught to not test for equality of two > floating point values (which also implies one did not test for the > negation of equality). One either tested for difference > (greater/less than) or for a delta between values being

Re: Floating point problem

2020-04-18 Thread Grant Edwards
On 2020-04-18, Souvik Dutta wrote: > I literally tried it!!! And it did not stop because I did not get any 1.0 > rather I got 0.999 But why does this happen. This is a simple math > which according to normal human logic should give perfect numbers which are > not endless. Then why does a

Re: Floating point problem

2020-04-18 Thread ast
Le 18/04/2020 à 15:07, Souvik Dutta a écrit : I have one question here. On using print(f"{c:.32f}") where c= 2/5 instead of getting 32 zeroes I got some random numbers. The exact thing is 0.40002220446049250313 Why do I get this and not 32 zeroes? 2/5 =

Re: Floating point problem

2020-04-18 Thread Aakash Jana
I am really enlightened by the amount of knowledge I received from a question that seemed so little to me.  On Sat, 18 Apr 2020, 8:08 pm Souvik Dutta Hmm understood. > > Souvik flutter dev > > On Sat, Apr 18, 2020, 7:36 PM Chris Angelico wrote: > > > On Sun, Apr 19, 2020 at 12:03 AM Souvik

Re: Floating point problem

2020-04-18 Thread Souvik Dutta
Hmm understood. Souvik flutter dev On Sat, Apr 18, 2020, 7:36 PM Chris Angelico wrote: > On Sun, Apr 19, 2020 at 12:03 AM Souvik Dutta > wrote: > > > > I literally tried it!!! And it did not stop because I did not get any 1.0 > > rather I got 0.999 But why does this happen. This is a

Re: Floating point problem

2020-04-18 Thread Souvik Dutta
Hmmm sorry please forgive me. I only did that because the question was relevant. Please forgive me. Sorry again. Souvik flutter dev On Sat, Apr 18, 2020, 7:52 PM DL Neil via Python-list < python-list@python.org> wrote: > On 19/04/20 1:51 AM, Souvik Dutta wrote: > > I literally tried it!!! And

Re: Floating point problem

2020-04-18 Thread DL Neil via Python-list
On 19/04/20 1:51 AM, Souvik Dutta wrote: I literally tried it!!! And it did not stop because I did not get any 1.0 rather I got 0.999 But why does this happen. This is a simple math which according to normal human logic should give perfect numbers which are not endless. Then why does a

Re: Floating point problem

2020-04-18 Thread Chris Angelico
On Sun, Apr 19, 2020 at 12:03 AM Souvik Dutta wrote: > > I literally tried it!!! And it did not stop because I did not get any 1.0 > rather I got 0.999 But why does this happen. This is a simple math > which according to normal human logic should give perfect numbers which are > not

Re: Floating point problem

2020-04-18 Thread Souvik Dutta
I literally tried it!!! And it did not stop because I did not get any 1.0 rather I got 0.999 But why does this happen. This is a simple math which according to normal human logic should give perfect numbers which are not endless. Then why does a computer behave so differently? On Sat, 18

Re: Floating point problem

2020-04-18 Thread Dan Sommers
On Sun, 19 Apr 2020 01:25:00 +1200 DL Neil via Python-list wrote: > On 19/04/20 1:07 AM, Souvik Dutta wrote: > > I have one question here. On using print(f"{c:.32f}") where c= 2/5 instead > > of getting 32 zeroes I got some random numbers. The exact thing is > >

Re: Floating point problem

2020-04-18 Thread DL Neil via Python-list
On 19/04/20 1:07 AM, Souvik Dutta wrote: I have one question here. On using print(f"{c:.32f}") where c= 2/5 instead of getting 32 zeroes I got some random numbers. The exact thing is 0.40002220446049250313 Why do I get this and not 32 zeroes? Approximating decimal numbers as binary

Re: Floating point problem

2020-04-18 Thread Souvik Dutta
I have one question here. On using print(f"{c:.32f}") where c= 2/5 instead of getting 32 zeroes I got some random numbers. The exact thing is 0.40002220446049250313 Why do I get this and not 32 zeroes? On Fri, 17 Apr, 2020, 6:25 pm ast, wrote: > Le 17/04/2020 à 13:40, Aakash Jana a

Re: Floating point problem

2020-04-17 Thread ast
Le 17/04/2020 à 13:40, Aakash Jana a écrit : I am running python 3.8 only but my issue is I need more zeroes after my result. I want 2/5 = 0.40 But I am only getting 0.4 f"{2/5:.6f}" '0.40' -- https://mail.python.org/mailman/listinfo/python-list

Re: Floating point problem

2020-04-17 Thread Peter Otten
Aakash Jana wrote: > I am running python 3.8 only but my issue is I need more zeroes after my > result. > I want 2/5 = 0.40 > But I am only getting 0.4 This is either a formatting problem >>> value = 0.4 >>> print(f"{value:10.6f}") 0.40 or -- if you want to *calculate* with a fixed

Re: Floating point problem

2020-04-17 Thread Rhodri James
On 17/04/2020 12:40, Aakash Jana wrote: I am running python 3.8 only but my issue is I need more zeroes after my result. I want 2/5 = 0.40 But I am only getting 0.4 When you just print or display a floating point number, Python only uses as many digits as needed if the answer happens to

Re: Floating point problem

2020-04-17 Thread Aakash Jana
I am running python 3.8 only but my issue is I need more zeroes after my result. I want 2/5 = 0.40 But I am only getting 0.4 On Fri, 17 Apr 2020, 5:08 pm Peter Otten <__pete...@web.de wrote: > Aakash Jana wrote: > > > I am calculating couple of ratios and according to the problem there must

Re: Floating point problem

2020-04-17 Thread Peter Otten
Aakash Jana wrote: > I am calculating couple of ratios and according to the problem there must > be a 6 decimal precision. But when I print the result I only get one 0. > E.g:- 2 / 5 = 0.40 but I am only getting 0.4 Make sure that you are using Python 3, not Python 2 or use at least one

Floating point problem

2020-04-17 Thread Aakash Jana
I am calculating couple of ratios and according to the problem there must be a 6 decimal precision. But when I print the result I only get one 0. E.g:- 2 / 5 = 0.40 but I am only getting 0.4 -- https://mail.python.org/mailman/listinfo/python-list