Unexpected behaviour of math.floor, round and int functions (rounding)
dn
PythonList at DancesWithMice.info
Fri Nov 19 17:21:27 EST 2021
On 20/11/2021 10.21, Chris Angelico wrote:
> On Sat, Nov 20, 2021 at 7:39 AM dn via Python-list
> <python-list at python.org> 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 people understand this?
>>> (Probably never. Sigh.)
>>
>>
>> Am not aware of any institution which teaches the inner-workings of a
>> CPU/ALU/FPU/GPU in a general programming class, ie "Programming" and
>> particularly "Coding", have diverged from "Computer Science" - in at
>> least this respect.
>>
>
> I think what I find annoying about this sort of thing is that people
> triumphantly announce that the computer is WRONG. It's the numeric
> equivalent of XKCD 169, and people get smug for the exact same reason,
> and perhaps unfortunately, do not get their arms cut off.
I guess I'm a little more familiar with the 'arrogant' side of this
phenomenon because in formal courses, eg uni, I'd predict at least one
such personality per group of 50~60 students!
However, cultural-components should be considered. There is no
requirement that the OP possess an advanced command of the English
language! (nor of Python, nor of computers/computing, ...) - see OP's name!
That said, it can be frustrating for those of us who see particular
problems over-and-over. If it were evidenced in a course, I would be
addressing a short-coming in the training materials - but there is no
one Python-course to suit us all...
Another behavior is to assume that because 'I' learned something
years-ago, so should 'everyone else'. Even superficial reflection
reveals that this just isn't true - particularly when we have an
education system which is largely based upon 'date of manufacture'!
(just because I'm older than you doesn't make me 'smarter' - although I
am definitely better-looking!)
The problem is not limited to the limitations of (hah!) floating-point
arithmetic. We've seen other questions 'here' and on "Tutor", which
illustrate lack(s) of understanding of basic relationships between
Python (software) and the hardware which runs its instructions, eg the
basic simplicity of using a 'paper computer' for debugging, the order of
precedence, that the RHS must happen before we can consider anything on
the LHS, ... I've met 'graduates' who have never even peered 'under the
hood' of a computer!
(Incidentally, I recently recommended against employing one such
otherwise extremely promising ("on paper" and 'in person') candidate.
Quizzed by A.N.Other on the panel (who was suitably-impressed), the
justification was an apparent total lack of curiosity - a personality
essential for problem-solvers! (IMHO)
Another one of my 'pet-peeves' (one of the many! Although, perhaps not
to the extent of chopping-off people's arms - no matter how Monty
Python-ic that might be, Sir Knight; is the lack of
spelling/typing/proof-reading skills evidenced by many. Criticising a
(school) teacher of my acquaintance for exactly this, I was bluntly told
"but you knew what I meant" and thus he felt "communication" had been
achieved. Um, yes, er, quite true - but at what effort, and who's effort?
I find this phenomenon in computer-people particularly fascinating,
given that Python (insert any other language-name here) is very
particular and finds "far" instead of "for" far-from acceptable (hah!
again!). Does this mean that their coding-technique is to
(almost-literally) throw stuff at Python and have the computer 'find'
all the typos and spelling-errors? (and if so, is this good use of
time/good technique?)
Thus, and on this, the members of the aforementioned panel had agreed
without discussion: any documents forwarded by a candidate which
contained spelling mistakes were 'binned' (trashed) without the usual
acceptance/tolerance/mercy one would apply to work-documents.
Training/education takes time and costs money. Accordingly, we have this
constant 'battle' between wanting to educate/acquire knowledge versus
the cost-benefit of some fact/skill which may never/rarely be used - and
the 'factory component' of choosing what is good for a group/for 'the
average trainee' cf what is so for the individual.
Entries on the back of a post-card...
--
Regards,
=dn
More information about the Python-list
mailing list