Unexpected behaviour of math.floor, round and int functions (rounding)
Peter J. Holzer
hjp-python at hjp.at
Sun Nov 21 13:40:45 EST 2021
On 2021-11-20 03:25:53 +0000, Ben Bacarisse wrote:
> Chris Angelico <rosuav at gmail.com> 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 mean
> > that 1/3 doesn't mean 1/3, or that 1/3 can't be represented?
>
> As you know, it is possible, but let's say we outlaw any finite notation
> for repeated digits... Why should I convert 1/3 to this particular
> apparently unsuitable representation?
Because you want to use tools which require that particular
representation? Like for example a pocket calculator?
> I will write 1/3 and manipulate that number using factional notation.
On paper, maybe. But if after a few more steps you have fractions like
37645 / 9537654, you might reconsider that choice.
In a program? Yes, there are cases where you really want to use
fractions. That's why fractions.Fraction exists in Python (and similar
datatypes in many other programming languages). But they have their
limits, too (no π or √2) and for most problems you don't need them. I
don't actually think I ever used fractions.Fraction in my 7 years of
Python programming. (I think I used Math::BigRat in Perl, but I've been
programming in Perl for a lot longer.)
hp
--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp at hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://mail.python.org/pipermail/python-list/attachments/20211121/c0311577/attachment.sig>
More information about the Python-list
mailing list