Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-23 Thread Chris Angelico
On Wed, Nov 24, 2021 at 3:04 AM ast wrote: > > Le 19/11/2021 à 21:17, Chris Angelico a écrit : > > On Sat, Nov 20, 2021 at 5:08 AM ast wrote: > >> > >> Le 19/11/2021 à 03:51, MRAB a écrit : > >>> On 2021-11-19 02:40, 2qdxy4rzwzuui...@potatochowder.com wrote: > On 2021-11-18 at 23:16:32 -0300

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-23 Thread ast
Le 19/11/2021 à 21:17, Chris Angelico a écrit : On Sat, Nov 20, 2021 at 5:08 AM ast wrote: Le 19/11/2021 à 03:51, MRAB a écrit : On 2021-11-19 02:40, 2qdxy4rzwzuui...@potatochowder.com wrote: On 2021-11-18 at 23:16:32 -0300, René Silva Valdés wrote: >>> 0.3 + 0.3 + 0.3 == 0.9 False

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-21 Thread Greg Ewing
On 22/11/21 4:58 am, Grant Edwards wrote: Yep, IIRC, it was a 4 bit processor because 4 bits is what it takes to represent one decimal digit. That was the Saturn, first used in the HP-71B. The original architecture (known as the "Nut")was weirder than that. It operated serially on 56 bit words

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-21 Thread Peter J. Holzer
On 2021-11-22 05:43:48 +1100, Chris Angelico wrote: > On Mon, Nov 22, 2021 at 5:42 AM Peter J. Holzer wrote: > > (I think I used Math::BigRat in Perl, but I've been > > programming in Perl for a lot longer.) > > Rodents Of Unusual Size? I don't think they exist... https://www.girlgeniusonline.co

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-21 Thread Peter J. Holzer
On 2021-11-21 10:57:55 +1100, Chris Angelico wrote: > And if decimal floating point were common, other "surprise" behaviour > would be cited, like how x < y and (x+y)/2 < x. Yup. Took me a bit to find an example, but this can happen. My HP-48 calculator uses a mantissa of 12 decimal digits. 6

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-21 Thread Chris Angelico
On Mon, Nov 22, 2021 at 5:42 AM Peter J. Holzer wrote: > (I think I used Math::BigRat in Perl, but I've been > programming in Perl for a lot longer.) > Rodents Of Unusual Size? I don't think they exist... ChrisA -- https://mail.python.org/mailman/listinfo/python-list

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-21 Thread Peter J. Holzer
On 2021-11-20 03:25:53 +, Ben Bacarisse wrote: > Chris Angelico writes: > > > It does mean exactly what it meant in grade school, just as 1/3 means > > exactly what it meant in grade school. Now try to represent 1/3 on a > > blackboard, as a decimal fraction. If that's impossible, does it mea

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-21 Thread Peter J. Holzer
On 2021-11-19 12:43:07 +0100, ast wrote: > Le 19/11/2021 à 03:51, MRAB a écrit : > > On 2021-11-19 02:40, 2qdxy4rzwzuui...@potatochowder.com wrote: > > > On 2021-11-18 at 23:16:32 -0300, > > > René Silva Valdés wrote: > > > > Hello, I would like to report the following issue: > > > > > > > > Work

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-21 Thread Grant Edwards
On 2021-11-21, Greg Ewing wrote: > On 21/11/21 2:18 pm, Grant Edwards wrote: >> My recollection is that it was quite common back in the days before FP >> hardware was "a thing" on small computers. CPM and DOS compilers for >> various languages often gave the user a choice between binary FP and >>

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Greg Ewing
On 21/11/21 2:18 pm, Grant Edwards wrote: My recollection is that it was quite common back in the days before FP hardware was "a thing" on small computers. CPM and DOS compilers for various languages often gave the user a choice between binary FP and decimal (BCD) FP. It's also very common for

RE: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Avi Gross via Python-list
- From: Python-list On Behalf Of Chris Angelico Sent: Saturday, November 20, 2021 8:03 PM To: python-list@python.org Subject: Re: Unexpected behaviour of math.floor, round and int functions (rounding) On Sun, Nov 21, 2021 at 11:39 AM Avi Gross via Python-list wrote: > > Can I suggest a

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Chris Angelico
On Sun, Nov 21, 2021 at 1:20 PM Rob Cliffe via Python-list wrote: > > > > On 21/11/2021 01:02, Chris Angelico wrote: > > > > If you have a number with a finite binary representation, you can > > guarantee that it can be represented finitely in decimal too. > > Infinitely repeating expansions come

RE: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Avi Gross via Python-list
om: Python-list On Behalf Of Chris Angelico Sent: Saturday, November 20, 2021 6:23 PM To: python-list@python.org Subject: Re: Unexpected behaviour of math.floor, round and int functions (rounding) On Sun, Nov 21, 2021 at 10:01 AM Avi Gross via Python-list wrote: > Computers generally

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Rob Cliffe via Python-list
On 21/11/2021 01:02, Chris Angelico wrote: If you have a number with a finite binary representation, you can guarantee that it can be represented finitely in decimal too. Infinitely repeating expansions come from denominators that are coprime with the numeric base. Not quite, e.g. 1/14 is

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Chris Angelico
On Sun, Nov 21, 2021 at 12:56 PM Avi Gross via Python-list wrote: > > Not at all, Robb. I am not intending to demean Mathematicians as one of my > degrees is in that subject and I liked it. I mean that some things in > mathematics are not as intuitive to people when they first encounter them, >

RE: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Avi Gross via Python-list
not expected to apply for a non-abelian case. -Original Message- From: Python-list On Behalf Of Rob Cliffe via Python-list Sent: Saturday, November 20, 2021 6:19 PM To: Subject: Re: Unexpected behaviour of math.floor, round and int functions (rounding) On 20/11/2021 22:59, Avi Gross

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Grant Edwards
On 2021-11-21, Chris Angelico wrote: >> I think there have been attempts to use a decimal representation in some >> accounting packages or database applications that allow any decimal numbers >> to be faithfully represented and used in calculations. Generally this is not >> a very efficient proce

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Chris Angelico
On Sun, Nov 21, 2021 at 11:39 AM Avi Gross via Python-list wrote: > > Can I suggest a way to look at it, Grant? > > In base 10, we represent all numbers as the (possibly infinite) sum of ten > raised to some integral power. Not infinite. If you allow an infinite sequence of digits, you create num

RE: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Avi Gross via Python-list
om: Python-list On Behalf Of Grant Edwards Sent: Saturday, November 20, 2021 5:24 PM To: python-list@python.org Subject: Re: Unexpected behaviour of math.floor, round and int functions (rounding) On 2021-11-20, Ben Bacarisse wrote: > You seem to be agreeing with me. It's the floating

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Chris Angelico
On Sun, Nov 21, 2021 at 10:55 AM Ben Bacarisse wrote: > > Grant Edwards writes: > > > On 2021-11-20, Ben Bacarisse wrote: > > > >> You seem to be agreeing with me. It's the floating point part that is > >> the issue, not the base itself. > > > > No, it's the base. Floating point can't represent

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Ben Bacarisse
Grant Edwards writes: > On 2021-11-20, Ben Bacarisse wrote: > >> You seem to be agreeing with me. It's the floating point part that is >> the issue, not the base itself. > > No, it's the base. Floating point can't represent 3/10 _because_ it's > base 2 floating point. Floating point in base 10

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Chris Angelico
On Sun, Nov 21, 2021 at 10:01 AM Avi Gross via Python-list wrote: > Computers generally use finite methods, sometimes too finite. Yes, the > problem is not Mathematics as a field. It is how humans often generalize or > analogize from one area into something a bit different. I do not agree with > a

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Rob Cliffe via Python-list
On 20/11/2021 22:59, Avi Gross via Python-list wrote: there are grey lines along the way where some mathematical proofs do weird things like IGNORE parts of a calculation by suggesting they are going to zero much faster than other parts and then wave a mathematical wand about what happens when

RE: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Avi Gross via Python-list
n floats but on the design not accommodating the precision needed or perhaps on the algorithm used not necessarily being expected to reach a certain level. -Original Message----- From: Python-list On Behalf Of Chris Angelico Sent: Saturday, November 20, 2021 5:17 PM To: python-list@python.or

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Chris Angelico
On Sun, Nov 21, 2021 at 9:22 AM Grant Edwards wrote: > > On 2021-11-20, Chris Angelico wrote: > > > But you learn that it isn't the same as 1/3. That's my point. You > > already understand that it is *impossible* to write out 1/3 in > > decimal. Is it such a stretch to discover that you cannot wr

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Grant Edwards
On 2021-11-20, Ben Bacarisse wrote: > You seem to be agreeing with me. It's the floating point part that is > the issue, not the base itself. No, it's the base. Floating point can't represent 3/10 _because_ it's base 2 floating point. Floating point in base 10 doesn't have any problem represent

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Grant Edwards
On 2021-11-20, Chris Angelico wrote: > But you learn that it isn't the same as 1/3. That's my point. You > already understand that it is *impossible* to write out 1/3 in > decimal. Is it such a stretch to discover that you cannot write 3/10 > in binary? For many people, it seems to be. There ar

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Chris Angelico
On Sun, Nov 21, 2021 at 8:32 AM Avi Gross via Python-list wrote: > > This discussion gets tiresome for some. > > Mathematics is a pristine world that is NOT the real world. It handles > near-infinities fairly gracefully but many things in the real world break > down because our reality is not infi

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Chris Angelico
On Sun, Nov 21, 2021 at 6:51 AM Ben Bacarisse wrote: > > Chris Angelico writes: > > > On Sat, Nov 20, 2021 at 3:41 PM Ben Bacarisse wrote: > >> > >> Chris Angelico writes: > >> > >> > On Sat, Nov 20, 2021 at 12:43 PM Ben Bacarisse > >> > wrote: > >> >> > >> >> Chris Angelico writes: > >> >>

RE: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Avi Gross via Python-list
This discussion gets tiresome for some. Mathematics is a pristine world that is NOT the real world. It handles near-infinities fairly gracefully but many things in the real world break down because our reality is not infinitely divisible and some parts are neither contiguous nor fixed but in some

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Ben Bacarisse
Chris Angelico writes: > On Sat, Nov 20, 2021 at 3:41 PM Ben Bacarisse wrote: >> >> Chris Angelico writes: >> >> > On Sat, Nov 20, 2021 at 12:43 PM Ben Bacarisse >> > wrote: >> >> >> >> Chris Angelico writes: >> >> >> >> > On Sat, Nov 20, 2021 at 9:07 AM Ben Bacarisse >> >> > wrote: >> >>

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-19 Thread Chris Angelico
On Sat, Nov 20, 2021 at 3:41 PM Ben Bacarisse wrote: > > Chris Angelico writes: > > > On Sat, Nov 20, 2021 at 12:43 PM Ben Bacarisse wrote: > >> > >> Chris Angelico writes: > >> > >> > On Sat, Nov 20, 2021 at 9:07 AM Ben Bacarisse > >> > wrote: > >> >> > >> >> Chris Angelico writes: > >> >>

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-19 Thread Ben Bacarisse
Chris Angelico writes: > On Sat, Nov 20, 2021 at 12:43 PM Ben Bacarisse wrote: >> >> Chris Angelico writes: >> >> > On Sat, Nov 20, 2021 at 9:07 AM Ben Bacarisse wrote: >> >> >> >> Chris Angelico writes: >> >> >> >> > On Sat, Nov 20, 2021 at 5:08 AM ast wrote: >> >> >> >> >> >>> 0.3 + 0.3 +

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-19 Thread Chris Angelico
On Sat, Nov 20, 2021 at 12:43 PM Ben Bacarisse wrote: > > Chris Angelico writes: > > > On Sat, Nov 20, 2021 at 9:07 AM Ben Bacarisse wrote: > >> > >> Chris Angelico writes: > >> > >> > On Sat, Nov 20, 2021 at 5:08 AM ast wrote: > >> > >> >> >>> 0.3 + 0.3 + 0.3 == 0.9 > >> >> False > >> > > >>

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-19 Thread Ben Bacarisse
Chris Angelico writes: > On Sat, Nov 20, 2021 at 9:07 AM Ben Bacarisse wrote: >> >> Chris Angelico writes: >> >> > On Sat, Nov 20, 2021 at 5:08 AM ast wrote: >> >> >> >>> 0.3 + 0.3 + 0.3 == 0.9 >> >> False >> > >> > That's because 0.3 is not 3/10. It's not because floats are >> > "unreliable"

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-19 Thread dn via Python-list
On 20/11/2021 10.21, Chris Angelico wrote: > On Sat, Nov 20, 2021 at 7:39 AM dn via Python-list > wrote: >>> 0.3 + 0.3 + 0.3 == 0.9 False >>> >>> That's because 0.3 is not 3/10. It's not because floats are >>> "unreliable" or "inaccurate". It's because the ones you're entering >>> are n

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-19 Thread Chris Angelico
On Sat, Nov 20, 2021 at 9:07 AM Ben Bacarisse wrote: > > Chris Angelico writes: > > > On Sat, Nov 20, 2021 at 5:08 AM ast wrote: > > >> >>> 0.3 + 0.3 + 0.3 == 0.9 > >> False > > > > That's because 0.3 is not 3/10. It's not because floats are > > "unreliable" or "inaccurate". It's because the on

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-19 Thread Ben Bacarisse
Chris Angelico writes: > On Sat, Nov 20, 2021 at 5:08 AM ast wrote: >> >>> 0.3 + 0.3 + 0.3 == 0.9 >> False > > That's because 0.3 is not 3/10. It's not because floats are > "unreliable" or "inaccurate". It's because the ones you're entering > are not what you think they are. > > When will peop

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-19 Thread Chris Angelico
On Sat, Nov 20, 2021 at 7:39 AM dn via Python-list wrote: > >> >>> 0.3 + 0.3 + 0.3 == 0.9 > >> False > > > > That's because 0.3 is not 3/10. It's not because floats are > > "unreliable" or "inaccurate". It's because the ones you're entering > > are not what you think they are. > > > > When will p

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-19 Thread dn via Python-list
On 20/11/2021 09.17, Chris Angelico wrote: > On Sat, Nov 20, 2021 at 5:08 AM ast wrote: >> Le 19/11/2021 à 03:51, MRAB a écrit : >>> On 2021-11-19 02:40, 2qdxy4rzwzuui...@potatochowder.com wrote: On 2021-11-18 at 23:16:32 -0300, René Silva Valdés wrote: > Working with floats i notic

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-19 Thread Chris Angelico
On Sat, Nov 20, 2021 at 5:08 AM ast wrote: > > Le 19/11/2021 à 03:51, MRAB a écrit : > > On 2021-11-19 02:40, 2qdxy4rzwzuui...@potatochowder.com wrote: > >> On 2021-11-18 at 23:16:32 -0300, > >> René Silva Valdés wrote: > >> > >>> Hello, I would like to report the following issue: > >>> > >>> Wor

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-19 Thread Mats Wichmann
On 11/18/21 19:40, 2qdxy4rzwzuui...@potatochowder.com wrote: On 2021-11-18 at 23:16:32 -0300, René Silva Valdés wrote: Hello, I would like to report the following issue: Working with floats i noticed that: int(23.99/12) returns 1, and int(23.999/12) returns 2 This im

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-19 Thread ast
Le 19/11/2021 à 12:43, ast a écrit : Le 19/11/2021 à 03:51, MRAB a écrit : On 2021-11-19 02:40, 2qdxy4rzwzuui...@potatochowder.com wrote: On 2021-11-18 at 23:16:32 -0300, René Silva Valdés wrote: Hello, I would like to report the following issue: Working with floats i noticed that: int(23.

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-19 Thread ast
Le 19/11/2021 à 03:51, MRAB a écrit : On 2021-11-19 02:40, 2qdxy4rzwzuui...@potatochowder.com wrote: On 2021-11-18 at 23:16:32 -0300, René Silva Valdés wrote: Hello, I would like to report the following issue: Working with floats i noticed that: int(23.99/12) returns 1, and int(

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-18 Thread MRAB
On 2021-11-19 02:40, 2qdxy4rzwzuui...@potatochowder.com wrote: On 2021-11-18 at 23:16:32 -0300, René Silva Valdés wrote: Hello, I would like to report the following issue: Working with floats i noticed that: int(23.99/12) returns 1, and int(23.999/12) returns 2 This

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-18 Thread 2QdxY4RzWzUUiLuE
On 2021-11-18 at 23:16:32 -0300, René Silva Valdés wrote: > Hello, I would like to report the following issue: > > Working with floats i noticed that: > > int(23.99/12) returns 1, and > int(23.999/12) returns 2 > > This implies that int() function is rounding ... It's

Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-18 Thread René Silva Valdés
Hello, I would like to report the following issue: Working with floats i noticed that: int(23.99/12) returns 1, and int(23.999/12) returns 2 This implies that int() function is rounding, which doesn't appear to be expected (documentation doesn't say anything about it). Lo