[Tutor] the binary math "wall"
Dave Angel
davea at ieee.org
Wed Apr 21 12:46:31 CEST 2010
Lowell Tackett wrote:
> --- On Tue, 4/20/10, Steven D'Aprano <steve at pearwood.info> wrote:
>
>
>> From: Steven D'Aprano <steve at pearwood.info>
>>
>> <snip>
>>
>> The simplest, roughest way to fix these sorts of problems
>> (at the risk
>> of creating *other* problems!) is to hit them with a
>> hammer:
>>
>>
>>>>> round(18.15*100) == 1815
>>>>>
>> True
>>
>
> Interestingly, this is the [above] result when I tried entered the same snippet:
>
> Python 2.5.1 (r251:54863, Oct 14 2007, 12:51:35)
> [GCC 3.4.1 (Mandrakelinux 10.1 3.4.1-4mdk)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>
>>>> round(18.15)*100 == 1815
>>>>
> False
>
>
> <snip>
But you typed it differently than Steven. He had round(18.15*100),
and you used round(18.15)*100
Very different. His point boils down to comparing integers, and when
you have dubious values, round them to an integer before comparing. I
have my doubts, since in this case it would lead to bigger sloppiness
than necessary.
round(18.154 *100) == 1815
probably isn't what you'd want.
So let me ask again, are all angles a whole number of seconds? Or can
you make some assumption about how accurate they need to be when first
input (like tenths of a second, or whatever)? If so use an integer as
follows:
val = round((((degrees*60)+minutes)*60) + seconds)*10)
The 10 above is assuming that tenths of a second are your quantization.
HTH
DaveA
More information about the Tutor
mailing list