Re: Currency Numbers
Re: Currency Numbers
- Subject: Re: Currency Numbers
- From: "Nigel Garvey" <email@hidden>
- Date: Thu, 22 Jun 2006 11:29:53 +0100
Paul Berkowitz wrote on Wed, 21 Jun 2006 20:38:13 -0700:
>Just to be awkward, here's a new twist. I can't recall how far back booleans
>can be coerced to integers (Panther?), but here's an alternative to
>
> (y ^ 2) ^ 0.5
>
>to get the absolute value of a number. Just for the hell of it. ;-)
>
>
> (-((y < 0) as integer) * y) + (((y > 0) as integer) * y)
And later:
> y * (((y > 0) as integer) - ((y < 0) as integer))
Lovely. :-) And when y _is_ 0, it doesn't matter that both propositions
are false: the final result is 0 anyway. Brilliant!
>OMM repeating the
>square/root method 10,000 times takes 3 ticks, while my boolean coercion
>method takes 15 ticks. So it's slower, but who would ever know? (12 ticks
>longer = 1/5th of a second. Over 10,000 loops, that's pretty good.)
You could claw back some of the speed with this one-coercion version:
y * (1 - 2 * ((y < 0) as integer))
NG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden