• 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: Andy Wylie <email@hidden>
  • Date: Sun, 22 Dec 2002 23:24:06 +1300

on Sat, 21 Dec 2002 22:00:19 -0500 Deivy Petrescu wrote:

>At 13:43 -0800 12/21/02, 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.
>
>Actually John's solution is valid for any OS since python is
>available for "classic" Mac OSes.
>
>I believe John's solution is actually the only solution that will
>provide an "accurate" result.
>Python handles numbers better, in general.
>
>After John proposed the Python solution , I decided to use OS X and
>came up with the following very simple script:
>
>-- requires OS X
>set z to "123456798"
>set z1 to "876543392"
>set k to do shell script "awk 'BEGIN {print " & z & "*" & z1 & "} END{}'"
>
>--108215240484378816
>
>However, it stops there. It is not very precise for larger numbers,
>while python is. (see note at the bottom)
>
>On the other hand if the number is not larger than 10^18 or 10^19
>then, this script is simpler and faster albeit being X only.
>
>For an AS vanilla solution

this using Smile's 'display' seems ok for sub +14

to ntxt(n)
try
set myzeros to
"000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000"
set dot to (0.1 as string)'s item 2
set nEx to display n --Smile- n as string unmolested
set E to (offset of "E" in nEx)
if (E + 1) = 1 then return nEx
set n to (character 1 of nEx) & (nEx's text 3 thru (E - 1)) as
string
set x to (nEx's text (E + 2) thru -1 as string) as number
if (nEx's character (E + 1)) = "-" then
return {nEx, ("0" & dot & myzeros's text 1 thru (x - 1)) & n}
end if
set _integer to ((n & myzeros)'s text 1 thru (x + 1)) as string
if x greater than or equal to 14 then
set _decimal to ""
else if (count n) > (x + 1) then
set _decimal to dot & (n & myzeros)'s text (x + 2) thru ((count
n))
else
set _decimal to ""
end if
return {nEx, _integer & _decimal}
on error m
return {nEx, n}
end try
end ntxt

ntxt(2.88347330826156E+12 * 13)
-- > {"3.74851530074003E+13", "37485153007400.3"}


_____________________________ Andy
_______________________________________________
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.

  • Prev by Date: Re: SE2 script snippet for Mouse Speed fails???
  • Next by Date: Script Editor 2.0 dict viewing
  • Previous by thread: Re: BIG number as string
  • Next by thread: Re: BIG number as string
  • Index(es):
    • Date
    • Thread