[Glass] 0.01 copy == 0.01

Martin McClure martin.mcclure at gemtalksystems.com
Thu Feb 27 08:05:18 PST 2014


On 02/27/2014 06:56 AM, James Foster wrote:
> On Feb 27, 2014, at 4:58 AM, Mariano Martinez Peck <marianopeck at gmail.com> wrote:
>
>> 0.01 copy == 0.01
>> -> true
>>
>> So...is this a compiler optimization? Is it something related to the fact that SmallDouble are immediate objects?
>
> It is not a compiler optimization but a side-effect of the fact that (as you note) SmallDouble are immediate objects so there are never any distinct copies. The behavior is similar to the following:
>
> 42 copy == 42. “true”
> $a copy == $a. “true”
> nil copy == nil. “true"
> true copy == true. “true”

SmallDoubles, like SmallIntegers, have a limited (though fairly large) 
range. Integer operations on SmallIntegers can produce a result that 
cannot fit in a SmallInteger, so the result is a LargeInteger. 
Similarly, operations on SmallDoubles can produce a result that is 
either too close to zero (but not exactly zero) or too far from zero to 
be represented as a SmallDouble, so the result will in those cases be a 
Float.

Regards,

-Martin


More information about the Glass mailing list