Unexpected result of negating a property numerical value

Here’s a weird one:

property x : -1.5
-- As expected:
-x --> 1.5
-(x) --> 1.5
-(get my x) --> 1.5
(my x) * -1 --> 1.5
-- But:
-(my x) --> 2
-(my x's contents) --> 2

In the latter two cases, it appears that “my x” is coerced to an integer value before being negated. Is this a known phenomenon? Is there an explanation for the coercion to an integer value?

Browser: Safari 536.28.10
Operating System: Mac OS X (10.8)

Interesting! I can’t guess the mechanics, but it’s apparently something to do with negating something which isn’t in itself a real. (‘my x’ is a reference to a variable.) Similarly:

set y to 1.5
-(y as text) --> -2

Thank you for pointing out the similar behavior when coercing numerical text. It suggests at least one possible mechanism of what may be going on under the hood.

May I ask for clarification on a couple of basic questions concerning properties:

(1) How does Applescript’s handling of a property referenced alone (x) differ from that when it is referenced with its owner (my x)? In the current example, -(x) and -(my x) return different values. Likewise when one uses properties to enhance the execution speed of repeat loops, speed enhancement is realized only when the property’s owner is explicitly referenced (my x) but not if it is omitted (x).

(2) Also, what is actually returned by the “contents of” operator? In the current example, I would have expected -(my x’s contents) to return 1.5 and not 2. Is it that the underlying value stored in a property is different from what it seems at first glance (a negative real number in the current example)?

The point here is that where you’re getting the result 2, the negation is being applied directly to the references, not to whatever would be returned by those references were they allowed to return results first. ‘-(my x)’ returns 2 because that’s the unexpected result of trying negate the reference ‘my x’. ‘-(get my x)’ returns 1.5 because the value of x is got first and it’s that value which is then negated. In ‘-(my x’s contents)’, ‘my x’s contents’ is itself a reference in the context of the source code!

The ‘contents’ operator would normally be used where the value of a variable is an AppleScript reference and you want the value at the end of that reference:

set a to -1.5
set b to a reference to a

return {b, b's contents} --> {a of «script», -1.5}

But a reference like this will usually be resolved automatically if you want to do something with the end-value rather than simply ‘get’ it, negate it, or test if it’s equal to something else:

set a to -1.5
set b to a reference to a

return b * -1 --> 1.5 (automatic dereference for multiplication)

A big stumbling block was thinking that ‘(my x’s contents)’ would return the underlying value, but understanding that both ‘(my x’s contents)’ and ‘(my x)’ are both treated as references in the current example clarifies why they both return the same result. Excellent, thank you for that explanation.