[Python-ideas] Re: Adding fixed-point decimals as an option to replace floating-point

2019-11-14 Thread Wes Turner
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 
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-le...@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/4PYR7MP47ZFQXMPIN5AWTDHMQO5W2UK6/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@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/34WRUQPL6YM5L5ZP52QMDY2O7XYWU6KN/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Adding fixed-point decimals as an option to replace floating-point

2019-11-14 Thread Chris Angelico
On Fri, Nov 15, 2019 at 9:53 AM Greg Ewing  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
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@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/5MYWGMOPTMTHE7HFKLPVVADGKMOXXPJN/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Adding fixed-point decimals as an option to replace floating-point

2019-11-14 Thread Greg Ewing

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-le...@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/4PYR7MP47ZFQXMPIN5AWTDHMQO5W2UK6/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Adding fixed-point decimals as an option to replace floating-point

2019-11-14 Thread Chris Angelico
On Fri, Nov 15, 2019 at 4:04 AM  wrote:
>
> Does decimal make this:
> 4.1 + 0.1
> produce 4.2 instead of 4.18?

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
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@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/CMY6MGTHILXXZE323S2J6TU7OD7JQSFX/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Adding fixed-point decimals as an option to replace floating-point

2019-11-14 Thread MRAB

On 2019-11-14 17:10, Brett Cannon wrote:


On Thu, Nov 14, 2019 at 9:04 AM > wrote:


Does decimal make this:
4.1 + 0.1
produce 4.2 instead of 4.18?


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.

___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@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/C22DFDLKXDPP6EBTNH6LZFNXSJUQFV7W/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Adding fixed-point decimals as an option to replace floating-point

2019-11-14 Thread Brett Cannon
On Thu, Nov 14, 2019 at 9:04 AM  wrote:

> Does decimal make this:
> 4.1 + 0.1
> produce 4.2 instead of 4.18?
>

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-le...@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/AXXMVUXSXKBFHI2D2ILCSDM65O6KEVR4/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@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/KGJZMJTR42SELTRAOSIZXGDN73SYSDNX/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Adding fixed-point decimals as an option to replace floating-point

2019-11-14 Thread awesomecronk
Does decimal make this:
4.1 + 0.1
produce 4.2 instead of 4.18?
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@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/AXXMVUXSXKBFHI2D2ILCSDM65O6KEVR4/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Adding fixed-point decimals as an option to replace floating-point

2019-11-14 Thread Jonathan Goble
On Thu, Nov 14, 2019 at 8:49 AM  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.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@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/A3F7PRZ532IELPZVN2YNETYN5XCV7KQA/
Code of Conduct: http://python.org/psf/codeofconduct/