On Tue, Jan 30, 2007 at 06:02:59PM +0100, TSa wrote: : HaloO, : : Luke Palmer wrote: : >When do we do integer/rational math and when do we do floating point math? : : Since we have now flooring semantics on modulus and division I wonder : how the coercion of nums to ints takes place. Does it also use floor? : E.g. is @array[-0.3] accessing the last element or is it truncating : to zero and indexing from the front?
Perl 5 truncates, I believe. One could argue that floor is better behaved, but the 0/-1 transition in subscripts is totally cork-brained anyway, so I don't think it really matters if our numbers behave when wrapping around the end of an array. Interestingly, negative fractions, if truncated, would give us a way to talk about the element off the end of the array, presuming that the endness of the subscript is determined from the sign before it is truncated: push @array, 42; @array[-0.1] = 42; # same thing @array[-0.0] = 42; # same thing? Since -0.0 is a possible Num representation, that last one probably works. But @array[-0] probably doesn't, since Int probably doesn't represent -0, and the constant folder would remove the sign before the subscript can see it. But it probably doesn't matter. If one really wants "infinite" modular arrays, then you probably just say @array[$x % @array] or some such, which gives you the floor semantics. Larry