Re: String to sum
Re: String to sum
- Subject: Re: String to sum
- From: Martin Orpen <email@hidden>
- Date: Wed, 13 Oct 2004 01:38:08 +0100
Title: Re: String to sum
on 13/10/04 12:18 am, Mr Tea at email@hidden wrote:
> Er, yes, but what does this mean? What is ‘scale=8’? what is ‘| bc –s2’?
> Perhaps it does what’s needed here but I like to understand what’s going on
> in my scripts, rather than just pasting in ‘magic code’ that works because
> it works. I'm not completely averse to the use of shell script capabilities
> in AppleScript, but don't want to learn a load of stuff that duplicates what
> AS can do already.
Ignore the "-s2" - and I promise to read the next post and run the script *before* I send it :-(
The "scale" is the number of decimal places that you want returned - 8 in this case.
"bc" is just a calculator. It's preferable to using AS because you can use it for really *big* numbers and it's fast.
Like all shell stuff, it can be extended and made more useful by writing your own shell scripts. I've written one called "mybc" which makes it easier for me to feed in big numbers from AppleScript. (I also use -s as a modifier for mybc, which is why I made the mistake of leaving it in.)
So, if I use this corrected version:
set biglist to {}
set opList to {"*", "+", "/", "-"}
repeat 1000 times
set end of biglist to random number from 1 to 1000
set end of biglist to some item of opList
end repeat
set n to do shell script "echo \"scale=8 \n" & (biglist as string) & "1\" | bc"
n
I can get the result of 1000 ops to 8 decimal places in around 3 seconds (most of which is AS generating the list). You’d have to do a lot of work to get AppleScript to crunch numbers like that.
Regards
--
Martin Orpen
Idea Digital Imaging Ltd -- The Image Specialists
http://www.idea-digital.com
_______________________________________________
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