So we could build on this
On 15 April 2016 at 11:10, Ben Bacarisse wrote:
>> from fractions import Fraction
>>
>> def exact_sum(nums):
>> return sum(map(Fraction, nums))
>>
>> This will give you the exact result with precisely zero rounding
>> error. You can convert it to float at the end.
>
Oscar Benjamin writes:
> On 15 April 2016 at 11:10, Ben Bacarisse wrote:
>> Oscar Benjamin writes:
>>
>>> On 15 April 2016 at 10:24, Robin Becker wrote:
>>
yes indeed summation is hard :(
>>>
>>> Not with Fraction it isn't:
>>>
>>> from fractions import Fraction
>>>
>>> def exact_sum(num
On 15 April 2016 at 11:10, Ben Bacarisse wrote:
> Oscar Benjamin writes:
>
>> On 15 April 2016 at 10:24, Robin Becker wrote:
>
>>> yes indeed summation is hard :(
>>
>> Not with Fraction it isn't:
>>
>> from fractions import Fraction
>>
>> def exact_sum(nums):
>> return sum(map(Fraction, nu
Tony van der Hoff writes:
> On 15/04/16 11:10, Ben Bacarisse wrote:
>> Oscar Benjamin writes:
>>
>>> On 15 April 2016 at 10:24, Robin Becker wrote:
>>
yes indeed summation is hard :(
>>>
>>> Not with Fraction it isn't:
>>>
>>> from fractions import Fraction
>>>
>>> def exact_sum(nums):
>>>
On 15/04/16 11:10, Ben Bacarisse wrote:
Oscar Benjamin writes:
On 15 April 2016 at 10:24, Robin Becker wrote:
yes indeed summation is hard :(
Not with Fraction it isn't:
from fractions import Fraction
def exact_sum(nums):
return sum(map(Fraction, nums))
This will give you the exa
Oscar Benjamin writes:
> On 15 April 2016 at 10:24, Robin Becker wrote:
>> yes indeed summation is hard :(
>
> Not with Fraction it isn't:
>
> from fractions import Fraction
>
> def exact_sum(nums):
> return sum(map(Fraction, nums))
>
> This will give you the exact result with precisely zer
On 15 April 2016 at 10:24, Robin Becker wrote:
> On 13/04/2016 18:05, Random832 wrote:
> .
>>
>>
>> No, it doesn't. Sum works on any type that can be added (except
>> strings), it can't make any assumptions about the characteristics of
>> floating point types. For non-numeric types, the ad
On 13/04/2016 18:05, Random832 wrote:
.
No, it doesn't. Sum works on any type that can be added (except
strings), it can't make any assumptions about the characteristics of
floating point types. For non-numeric types, the addition operator may
not be semantically commutative or associati
Robin Becker wrote:
> Does anyone know if sum does anything special to try and improve accuracy?
> My simple tests seem to show it is exactly equivalent to a for loop
> summation.
If you are worried about accuracy and your values are floating point numbers
use math.fsum():
"""
fsum(...)
fsu
Robin Becker writes:
> Does anyone know if sum does anything special to try and improve
> accuracy? My simple tests seem to show it is exactly equivalent to a
> for loop summation.
You want math.fsum.
--
https://mail.python.org/mailman/listinfo/python-list
On Wed, Apr 13, 2016, at 12:51, Robin Becker wrote:
> Does anyone know if sum does anything special to try and improve
> accuracy? My
> simple tests seem to show it is exactly equivalent to a for loop
> summation.
No, it doesn't. Sum works on any type that can be added (except
strings), it can't
Does anyone know if sum does anything special to try and improve accuracy? My
simple tests seem to show it is exactly equivalent to a for loop summation.
--
Robin Becker
--
https://mail.python.org/mailman/listinfo/python-list
12 matches
Mail list logo