Re: Scientific notation to text
Re: Scientific notation to text
- Subject: Re: Scientific notation to text
- From: Paul Skinner <email@hidden>
- Date: Mon, 14 May 2001 10:57:44 -0400
on 5/14/01 3:14 AM, Paul Berkowitz wrote:
>
On 5/13/01 11:55 PM, "Michelle Steiner" <email@hidden> wrote:
>
>
> On 5/13/01 10:21 PM, Paul Berkowitz <email@hidden> wrote:
>
>
>
>> Now try just compiling (don't run it yet):
>
>>
>
>> 1.94055698299304
>
>>
>
>> It compiles to:
>
>>
>
>> 1.940556982993
>
>>
>
>> so it looks as if those final '04' digits put it out of the reach of
>
>> AppleScript reals. That's what's happening when your typing is evaluated
>
>> before the 'as text' coercion even takes place. I know that the final two
>
>> digits don't disappear when you tack on 'E-4' and then compile or run the
>
>> resulting number, but I bet that they would get ignored in a calculation.
>
>
>
> Enter this into the script editor.
>
>
>
> 1.94055698299304 = 1.940556982993
>
>
>
> Compile it; it now displays this:
>
>
>
> 1.940556982993 = 1.940556982993
>
>
>
> Run it.
>
>
>
> --> false
>
>
>
We've been here before, a few months ago. It has to do with the binary
>
representation of some decimal numbers as not exact. So the above "equation"
>
will represent two different binaries which do not equal each other but
>
which both round to the same decimal real. I don't know why, in that case,
>
the longer number is truncated in decimal version - I'd guess because there
>
are too many significant places to represent accurately in binary.
Interesting, The number that I pasted into my email was the result of a
division of two random numbers that I was using for testing purposes.
So, AppleScript can create and display 14 digit real numbers as a result
of a calculation and it retains their true value, as in your example above,
but it won't show that true value unless it is the result of a calculation.
That seems very strange.
JFF...
1.123456789E+8 / 1.123456789012E+8
-->0.999999999989
-- 12 digits.
1.123456789E+8 / 1.123456789012E+9
-->0.099999999999
-- 12 digits.
1.123456789E+8 / 1.123456789012E+10
-->0.01
-- 2 digits!
1.123456789E+8 / 1.123456789012E+11
-->9.99999999989319E-4
-- 14 digits.
1.123456789E+8 / 1.123456789012E+12
-->9.99999999989319E-5
-- 14 digits.
1.123456789E+8 / 1.123456789012E+308
--> 9.99999999989319E-301
--14 digits.
Maximum size for a value is right around here somewhere.
1.123456789E+8 / 1.123456789012E+309
-->Syntax error. The result of a numeric operation was too large.
Maximum user defined length of a real is 12 decimal places.
1.123456789E+8 / 1.1234567890123E+12
-->Syntax Error. Some Object.
I think my mother explained this to me as a child when she said ...
"Don't play so close to the edge, you never know what might happen!".
I'm still working on how to capture this 14 digit value as text.
Not that it is literally or mathematically 'significant' : )
Thanks,
--
Paul Skinner