On 06Mar2014 18:08, Mark H. Harris firstname.lastname@example.org wrote:
On Thursday, March 6, 2014 6:38:34 PM UTC-6, Chris Angelico wrote: Once again, the problem occurs only because you're using a float
literal, and 2.01 can't perfectly round-trip.
That's pretty much the value you had (I have a few more digits there, the square rooting and squaring probably cost some accuracy),
hi Chris, yes, you are completely missing the point. We are talking past each other. I DO NOT need you to explain to me why the is working just like its supposed to... its broken and should not work this way !
If you write a number on paper do you write down '2.01' ?
Do you write down d(2.01) ?
Do you write down 2.01d ?
(or) do you write down 2.01 ?
When I want a square-root from python I want to enter s1=sqrt(2.01)
<====== this is normal
So essentially you are saying: when I write Python code I do not want to have to put in all this special notation to get the actual value which I naturally mean.
And if you write 2.01, you mean 2 + 1/100, without roundoff because you do not want to be working in a system which would round that off. i.e. a Decimal internal representation because you're writing a number in base 10.
To my mind you want a Python _parser_ mode, because inside python, given the various numeric classes abounding, the actual _mechanisms_ already exist.
So really you want to have a way of saying to the parser: in the code, 2.01 is not transformed into an IEEE float with some loss of precision, it is transformed into a Decimal floating point number, with no loss of precision.
There are, it seems to me, two basic ways to approach this.
The easy one is give Python something like:
from __the_far_far_future__ import Decimal_numbers
and have decimal literals converted into those instead of Python "floats".
The alternative is the implement a Python class, let us call it "AbtractNumber", which stores the literal text you put in the programme code "2.01" and converts it, _when used_, to a suitable python type with the right semantics.
Either would get you code where:
x = 2.01
is stored without loss of precision, and may get you the behaviour you're after.
Which of these more closely matches your desires?
Please try to be precise. Examples don't quite do it without some rather precise accompanying lagunage which says what specific things the example is meant to illustrate.
If one of my two suggestions above is very close to what you're after, please present an example where one suggestion does what you want and where the other would not, with an explaination of why.
Cameron Simpson email@example.com
Careful and correct use of language is a powerful aid to straight thinking, for putting into words precisely what we mean necessitates getting our own minds quite clear on what we mean. - W.I.B. Beveridge