Re: unicode text coercion to number bug?
Re: unicode text coercion to number bug?
- Subject: Re: unicode text coercion to number bug?
- From: Paul Berkowitz <email@hidden>
- Date: Tue, 14 Sep 2004 13:19:07 -0700
On 9/14/04 12:10 PM, "Mark Butcher" <email@hidden> wrote:
> Several pointed out that you shouldn't rely on automatic coercions
> unless you are 100% sure of them. I had tested this with divide, and it
> worked, so I assumed it would automatically coerce with multiply also.
> My point is that it should either work for _both_ multiply and divide,
> or not. My own feeling in this case is that it should not work. But how
> can you ever be 100% sure anyway? Test for all the math operators (in
> this case) to see if they all work? We assume that if it works for one
> math operator, it works for the others. If not, it's a bug.
The way to be sure is not to use automatic coercions but to use _explicit_
coercions. Explicit coercions are covered by "the rules". This will always
work:
set resultFromStudioTextBox to (1.2 as Unicode text) -- for example
(resultFromStudioTextBox as number) / 3
(resultFromStudioTextBox as number) * 3
'as number' is an explicit coercion. It will always work in arithmetic
expressions. Use it. If you specifically want the result 'as real' even when
it could possibly work for an integer, then use 'as real' instead of 'as
number'. The divider operator " / " will always produce a real in any case
(and will coerce the 'number' nominator to a real from an integer if need
be) so it's really only the multiplication operator ( * ) where this
matters. To be consistent, use 'as real'.
--
Paul Berkowitz
_______________________________________________
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