Fwd: Re: Exponential notation [was: Re: How to calculate/process this one?]
Fwd: Re: Exponential notation [was: Re: How to calculate/process this one?]
- Subject: Fwd: Re: Exponential notation [was: Re: How to calculate/process this one?]
- From: email@hidden (Michael Sullivan)
- Date: Sat, 27 Apr 2002 18:00:14 -0400
- Organization: Society for the Incurably Pompous
On 4/27/02 8:15 AM, "Paul Berkowitz" <email@hidden> wrote:
>
>> So, my question is, at what point does AppleScript start using exponential
>
>> notation to represent numbers? And is there a way to convert exponential
>
>> notation into, er, regular notation? (Ok. That was 2 questions.)
>
> For integers:
>
> 536870911
>
> + 1
>
> = 5.36870912E+8
>
> = 2^29
>
Since this is true also of negative integers, and of 0, it means that
>
AppleScript can handle up to 2^30 integers. I think these are also known as
>
"longs". After that it has to coerce integers to reals, which i think are
>
called "floating point" calculations. I'm not sure how many of those there
>
are, or if there is any limit. There is also something called "small
>
integer" in AppleScript, which are also known as "shorts". The limits for
>
those are -32768 and 32767, so there are 2^16 of those. I think that other
>
programs make more of a distinction between shorts and longs than
>
AppleScript does.
You can actually work with real numbers as if they are integers up to
somewhere around 1.mumbleE+14.
I was playing around in this range trying to find good prime numbers for
pseudoRand (which led to working with Arthur and then Nigel on some
major overhauls to his PrimeNumLib, which will get posted whenever we
stop finding teeny bugs and adding monstrous new features).
I never did write the script to figure exactly what the highest number
is but it's in the E14 range.
Okay, so now I did, and it's actually in the E15 range.
set i to 2
repeat with exp from 12 to 1 by -1
repeat until i = (i - 1) or (i - 2) = (i - 3)
set i to i + 10 ^ exp
end repeat
set i to i - 10 ^ exp
end repeat
i
--> 9.00719925474099E+15
That's the largest number that applescript can actually handle *as* an
integer. After that, you don't have enough precision. That turns out
to be (2^53).
What's interesting is that AS keeps a 15th decimal place up to this
point even though it won't display it. (I'm sure they chose not to
display it and to consider entries of it as a syntax error, because they
couldn't guarantee it working for all possible values).
Fortunately we can expose it:
(2^53)
--> 9.00719925474099E+15
(2^53-1)
--> 9.00719925474099E+15
(2^53) mod 1000
--> 992
(2^53-1) mod 1000
--> 991
So, i reran the above script with the last line as:
{i, i mod 1000, i + 1 mod 1000}
--> {9.00719925474099E+15, 992.0, 992.0}
the largest number that AS can treat as an integer is:
9007199254740992
Now if I have the patience to wait for a prime finding algorithm to find
the closest prime smaller than this, I'll be updating pseudoRand again.
>
> For reals:
>
> 9999.9
>
> + .1
>
> = 1.0E+4
>
> = 10^4
>
>
This appears to be just a matter of notation, rather than any sort of "real"
>
limit (pardon the pun). I'm not sure if there's a limit to the number of E+
>
places, but I guess there must be. Let's try.
It is. I find it considerably annoying that AS puts reals into E+
notation at E+4, rather than waiting for a decently large number, like a
billion or trillion. Considering that there are 14+ significant digits
to work with, this wouldn't be a problem.
I'm very much not used to thinking in scientific notation for numbers
under 1 million or so, and I'll bet I'm not the only one.
>
OK. Somewhere between 1.797693134862E+308 and 1.797693134863E+308, the
>
"result of a numeric calculation was too large". (The first of those numbers
>
works, the second doesn't, with that error.) The limit for reals is
>
somewhere in there. Adding any more decimal places after the final '2'
>
creates a syntax error, so I have to stop here, long before the 307th
>
decimal place. I have no idea how many zillion this represents, nor what
>
power of 2 (or even if it could be represented as a power of 2 without using
>
E notation for the exponent itself!).
O ye of little faith, or appreciation for the power of exponentiation.
The exponent is a very manageable number. Remember 2^3.mumble = 10, and
the exponent would be log base10 of the big number (308.mumble) * log
base2 of 10 (3.mumble). So it won't be more than 4*309, which is 1236.
>
Does anyone know the significance of
>
this amazing number? Multiply by 2, because it works for negatives too.
It looks like 2^1024 - 1, or at least as close as AS can get with it's
15 digit floating point precision.
I was able to get a script to produce this number:
1.79769313486231E+308
the script was
(2^1023 - 1E+293)
2^1024
produces a "too large" error.
Note, I used my logarithm applemod to find 1024:
logarithm(2, 1.79769313486231E+308, 12)
-->1024
Now everybody go pump up my hits. :)
Although you should wait until I submit 1.1 where I will fix the slight
precision error that this exposed. Oops.
Trying to bump that number by the smallest amount possible:
logarithm(2, 1.79769313486232E+308, 12)
-- "too large" on compilation.
logarithm(2, 1.797693134862311E+308, 12)
--> syntax error on compilation
Oh, wait...
logarithm(2, 1.79769313486231E+308 + 1.0E+293, 12)
-->1024.0
logarithm(2, 1.79769313486231E+308 + 5.0E+293, 12)
-->1024.0
logarithm(2, 1.79769313486231E+308 + 6.0E+293, 12)
--> "too large" error
So the highest number applescript will support is...
[drum roll please]
1.797693134862315 * 10^308
Essentially 2^1024 - 1, or as close as 16 digits precision can do
without going over.
If you add the negatives, you get 2^1025 - 1, which (if it was arbitrary
precision) would be the numbers that could be represented by 1024 bits.
Michael
--
Michael Sullivan
Business Card Express of CT Thermographers to the Trade
Cheshire, CT email@hidden
-------- End Forwarded Message --------
--
Michael Sullivan
Business Card Express of CT Thermographers to the Trade
Cheshire, CT email@hidden
_______________________________________________
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.