[Tutor] the binary math "wall"
lowelltackett at yahoo.com
Tue Apr 20 20:20:47 CEST 2010
>From the virtual desk of Lowell Tackett
--- On Tue, 4/20/10, Luke Paireepinart <rabidpoobear at gmail.com> wrote:
> From: Luke Paireepinart <rabidpoobear at gmail.com>
> Subject: Re: [Tutor] the binary math "wall"
> To: "Lowell Tackett" <lowelltackett at yahoo.com>
> Cc: "tutor" <Tutor at python.org>
> Date: Tuesday, April 20, 2010, 1:20 PM
> On Tue, Apr 20, 2010 at 11:58 AM,
> Lowell Tackett
> <lowelltackett at yahoo.com>
> > I'm running headlong into the dilemma of binary math
> representation, with game-ending consequences, e.g.:
> >>>> 0.15
> > 0.14999999999999999
> Yes, floats are slightly inaccurate.
> But I think your problem is that your math is wrong.
> You are assuming...
> If your equations cannot handle this, then coerce the value
> to 1.
> if .9999999 < i < 1.00001:
> i = 1
> And before you say "but that is just a hack", no, that is
> the nature...
> But you really just need to adapt...
> May I suggest another approach though?
> Consider this:
> >>> a = 18.15
> >>> a
> >>> a = '18.15'
> >>> degree, min = map(int, a.split('.'))
> >>> degree
> >>> min
> Supposing you get your input as a string.
> Basically the second you let your value end up stored as a
> there's no turning back...
> Eventually you will develop a distrust for floats...
> Hope that helps,
I was gonna go out jogging - and in a coupla hours check to see if anyone had tried to take this "on"; going out the door I decided to take a quick look. Ahem...
These responses just "blow me away" on a couple of levels. I'm choosing "Luke"'s offering as representative. Within <minutes> some great folks had read, parsed, and re-structured my query. My narrow focus yells out my inexperience...I was trying as hard as I could, with limited tools, to solve the issue. That's fine. But...the breadth and depth of the responses represent nothing short of a paradigm shift in my window into this world of "hacking".
Ya'll have insights of a scale unimagined in the confines of my "thinking box". (Now, I gotta go out and jog just to clear my head!) Then come back...and pull the blinds closed...and absorb; and come up for air in maybe a week or so. And only then, be able to offer my thanks with an objective sense of how much I've been helped today...Wow!
More information about the Tutor