Re: div bug
Re: div bug
- Subject: Re: div bug
- From: Paul Berkowitz <email@hidden>
- Date: Tue, 04 Aug 2009 02:31:52 -0700
- Thread-topic: div bug
On 8/4/09 12:38 AM, "Philip Aker" <email@hidden> wrote:
> On 2009-08-04, at 00:36:01, Bert Groeneveld wrote:
>
>> This is normal behaviour. The div operator is used to divide 2
>> numbers. Applescript converts both numbers to integers (if they're
>> not already integers), performs the division, and discards any
>> fractional remainder. The result is always an integer. Use / instead
>> of div.
>
> Oh, you're perfectly correct !
Am I misreading, or are these answers missing the point?
102.0 div 1 ought to yield 102, not 101.
>> set n to 1.015 * 100 --> 101.5
>> set n to n + 0.5 --> 102.0
>> n div 1 --> 101 --> (!)
>>
>> The workaround for the "affected routines" would be coercing n to
>> "small
>> real" (if you wish to preserve decimals) before using div.
Julifos did not mean to say he wanted to preserve decimals in the final
result. But rather that
set n to 1.015 * 100 --> 101.5
set n to n + 0.5 --> 102.0
(n as small real) div 1 --> 102
gets the right answer. (102)
So does:
set n to 1.015 * 100 --> 101.5
set n to n + 0.5 --> 102.0
n as integer --> 102
Since that's what he's apparently looking for, better to use this coercion.
--
Paul Berkowitz
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden
References: | |
| >Re: div bug (From: Philip Aker <email@hidden>) |