• 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: BIG number as string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: BIG number as string


  • Subject: Re: BIG number as string
  • From: has <email@hidden>
  • Date: Sun, 22 Dec 2002 15:22:02 +0000

John W Baxter wrote:

OK, here's a simple proof-of-concept of an approach very different from
those proposed. Useful for Mac OS X, recent enough to have shipped with
Python, or with Python installed by you in command line form.

-- Pick a path name,
-- Create a temporary file and write a Python program into it
-- Run the Python program and delete it

Smart. Can be simplified:

on multiply(a, b)
do shell script "python -c 'print " & a & " * " & b & "'"
end multiply

Seems to be good on whole numbers up to 10^16, beyond which it resorts to Sci notation. Python & Perl have excellent libraries though; perhaps there's something in those for number formatting?

...

Candidate AS method below. More portable than a 'do shell script' (much faster too, if speed is an issue). Hasn't been adequately tested, so no guarantees. Only does whole numbers, but shouldn't be hard to do fractional part as well.

on bigIntAsString(num)
set int to num div 1
if int is not num then error "Not a whole number." number -1703
set str to ""
repeat while int is greater than or equal to 10000
set str to (text -4 thru -1 of ("0000" & (int mod 10000 div 1))) & str
set int to int div 10000
end repeat
return ((int mod 10000) as string) & str
end bigIntAsString

Rounding errors in big numbers is still an issue, but that's a limitation of AS. Not much you can do about this, short of rolling your own types.

May be good up to 10^15 or so, but that's a guess. (Anyone know what point AS reals lose accuracy?)

has
--
http://www.barple.pwp.blueyonder.co.uk -- The Little Page of AppleScripts
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: BIG number as string
      • From: John W Baxter <email@hidden>
  • Prev by Date: Re: SE2 script snippet for Mouse Speed fails???
  • Next by Date: Re: Properties not retained
  • Previous by thread: Re: BIG number as string
  • Next by thread: Re: BIG number as string
  • Index(es):
    • Date
    • Thread