• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Currency Numbers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Currency Numbers
      • From: "Gary (Lists)" <email@hidden>
  • Prev by Date: Re: Intel UI scripting
  • Next by Date: to add icon on Safari's toolbar
  • Previous by thread: Re: Currency Numbers
  • Next by thread: Re: Currency Numbers
  • Index(es):
    • Date
    • Thread