An ideal improvement to python would be the introduction of fixed point decimals. Maybe make them adjustable with os.system(). To adjust, you would call os.system with the parameters ‘fixed’, 3, 15 to dictate fixed point math, three integer places, and 15 decimal places. Might be good for python 4 if this doesn’t gain enough traction before the 3.9 release. This would make them usable with python's generic math operators.
On Thu, Nov 14, 2019 at 8:49 AM awesomecronk@gmail.com wrote:
An ideal improvement to python would be the introduction of fixed point decimals. Maybe make them adjustable with os.system(). To adjust, you would call os.system with the parameters ‘fixed’, 3, 15 to dictate fixed point math, three integer places, and 15 decimal places. Might be good for python 4 if this doesn’t gain enough traction before the 3.9 release. This would make them usable with python's generic math operators.
Python already has the decimal module to do exactly this.
On Thu, Nov 14, 2019 at 9:04 AM awesomecronk@gmail.com wrote:
Does decimal make this: 4.1 + 0.1 produce 4.2 instead of 4.19999999999998?
Yes, see https://docs.python.org/3/library/decimal.html#module-decimal.
Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/AXXMVU... Code of Conduct: http://python.org/psf/codeofconduct/
On 2019-11-14 17:10, Brett Cannon wrote:
On Thu, Nov 14, 2019 at 9:04 AM <awesomecronk@gmail.com mailto:awesomecronk@gmail.com> wrote:
Does decimal make this: 4.1 + 0.1 produce 4.2 instead of 4.19999999999998?
Yes, see https://docs.python.org/3/library/decimal.html#module-decimal.
If you're talking about literal 4.1 and literal 0.1 in the code, then no.
It would be:
from decimal import Decimal print(Decimal('4.1') + Decimal('0.1'))
There have been suggestions in the past to add a suffix, e.g. 4.1d + 0.1d, given that the 'decimal' module is in the stdlib.
On Fri, Nov 15, 2019 at 4:04 AM awesomecronk@gmail.com wrote:
Does decimal make this: 4.1 + 0.1 produce 4.2 instead of 4.19999999999998?
The decimal module means that Decimal("4.1") is equal to 41/10 rather than 2308094809027379/562949953421312, and Decimal("0.1") is equal to 1/10 rather than 3602879701896397/36028797018963968. But in your source code, if you type 4.1, you are asking for the floating-point value 2308094809027379/562949953421312, just as if you say "hello" you are asking for a Unicode string containing those five characters/code points.
The problem here is not with addition, but with whether or not you have the number you think you do. So to get a different result, you have to start with different values.
ChrisA
On 15/11/19 7:39 am, Chris Angelico wrote:
But in your source code, if you type 4.1, you are asking for the floating-point value
The idea of providing decimal literals comes up from time to time, but so far it hasn't gotten anywhere. The problem is that it would make the core interpreter dependent on the Decimal module.
On Fri, Nov 15, 2019 at 9:53 AM Greg Ewing greg.ewing@canterbury.ac.nz wrote:
On 15/11/19 7:39 am, Chris Angelico wrote:
But in your source code, if you type 4.1, you are asking for the floating-point value
The idea of providing decimal literals comes up from time to time, but so far it hasn't gotten anywhere. The problem is that it would make the core interpreter dependent on the Decimal module.
Plus they have their own peculiarities, including that (x+y)/2 might not be between x and y. Also, run-time changes to the decimal context can't affect literals, which could cause very confusing behaviour.
ChrisA
FWIW, bigfloat (GNU MPFR) has arbitrary precision and rounding that can be set with `with` context managers: https://pythonhosted.org/bigfloat/
On Thursday, November 14, 2019, Greg Ewing greg.ewing@canterbury.ac.nz wrote:
On 15/11/19 7:39 am, Chris Angelico wrote:
But in your source code, if you type 4.1, you are asking for the floating-point value
The idea of providing decimal literals comes up from time to time, but so far it hasn't gotten anywhere. The problem is that it would make the core interpreter dependent on the Decimal module.
-- Greg _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at
https://mail.python.org/archives/list/python-ideas@python.org/message/4PYR7M...
Code of Conduct: http://python.org/psf/codeofconduct/