Re: [Python-ideas] Settable defaulting to decimal instead of float

2017-01-12 13:13 GMT+01:00 Stephan Houben <stephanh42@gmail.com>:
Most of the time one of my students talks to me about decimal vs
from __future__ import use_decimal_instead_of_float or any other import would be very good. The most important thing in my point of view is that I do not want to convert every variable every time to decimal. Accuracy is important for me (yes, 0.1 + 0.2 should equal to 0.3 , no more, no less ;-) ) And if it is mentioned, I would like to ask why binary floating point is "better". It is faster, I agree, but why "better"? Actually I create test automation (I am a senior QA eng), the fastest test case runs for about 1-2 minutes. I do not know the exact time difference between binary and decimal arithmetic, but I do not care with this. My test would run some microseconds faster. It does not matter at a minute range. In the tests I calculate with numbers with 4 decimal digits, and I need exact match. ;-) Actually I have a new colleague, they did image analysis, and the calculated much calculations, and they used a library (not python) that is accurate as well. Becasue accuracy was more important for them as well. BR George

On Fri, Jan 13, 2017 at 12:09 AM, George Fischhof <george@fischhof.hu> wrote:
Sounds like you want integer arithmetic. When you're working with something that goes to a known number of decimal places (eg money), it's often easiest and safest to redefine your unit (eg cents rather than dollars, or millimeters instead of meters) so you can use integers everywhere. Accurate AND fast! ChrisA

On 1/12/2017 8:09 AM, George Fischhof wrote:
And if it is mentioned, I would like to ask why binary floating point is "better". It is faster, I agree, but why "better"?
Binary numbers are more evenly spread out. Consider successive two diget numbers .99, 1.0, 1.1. The difference betweem the first two is .01 and that between the next pair is .1, 10 times as large. This remains true for .999, 1.00, 1.01 or any other fixed number of digits. For binary floats, the gap size only doubles. When I used slide rules, which have about 3 digits of accuracy, some decades ago, this defect of decimal numbers was readily apparent. -- Terry Jan Reedy

On Fri, Jan 13, 2017 at 12:09 AM, George Fischhof <george@fischhof.hu> wrote:
Sounds like you want integer arithmetic. When you're working with something that goes to a known number of decimal places (eg money), it's often easiest and safest to redefine your unit (eg cents rather than dollars, or millimeters instead of meters) so you can use integers everywhere. Accurate AND fast! ChrisA

On 1/12/2017 8:09 AM, George Fischhof wrote:
And if it is mentioned, I would like to ask why binary floating point is "better". It is faster, I agree, but why "better"?
Binary numbers are more evenly spread out. Consider successive two diget numbers .99, 1.0, 1.1. The difference betweem the first two is .01 and that between the next pair is .1, 10 times as large. This remains true for .999, 1.00, 1.01 or any other fixed number of digits. For binary floats, the gap size only doubles. When I used slide rules, which have about 3 digits of accuracy, some decades ago, this defect of decimal numbers was readily apparent. -- Terry Jan Reedy
participants (3)
-
Chris Angelico
-
George Fischhof
-
Terry Reedy