List Info

Thread: Re: overload "0+" doesn't handle integer results




Re: overload "0+" doesn't handle integer results
user name
2007-10-08 15:51:52
I'm really on a roll here.  I think I know how to fix all of
this
stuff, but there are dozens of fuctions to tackle.   Please
disregard
this patch (and the previous ones, too).  I'll work all this
out and
submit one big patch that does it all.  Sorry for the
noise.

> Zefram wrote:
> > It works OK for plain printf "%d", but
not for addition.
> > Also doesn't work for subtraction, negation,
> > multiplication, division, remainder.  Does work
for bit
> > shift and bitwise OR.  Perhaps some code factoring
is
> > called for.
>
> Jerry D. Hedden wrote:
> > The attached patch adds tests for these to
lib/overload.t.
> > The tests are skipped if not using 64-bit ints.
> > The following tests (which fail for me) are set as
TODO:
> >     0+ (addition)
> >     subtraction
> >     multiplication
> >     division
> >     modulo (%)
> >     exponentiation (**)
> >     abs()
>
> The attached patch (which supercedes my previous
patches on
> the matter) fixes the above problem for 'abs' and
'neg'
> overloading.  I added more tests as well.
>
> The patch can be check using the following:
>
> ./perl -Ilib -lwe '{ package t0; sub mynum  use
> overload "0+" => &mynum, fallback
=> 1; } printf "%dn",
> abs(t0::mynum); printf "%dn", abs(bless({},
"t0"))'
>
> ./perl -Ilib -lwe '{ package t0; sub mynum  use
> overload "0+" => &mynum, fallback
=> 1; } printf "%dn", -&t0::mynum;
> printf "%dn", -bless({}, "t0")'

Re: overload "0+" doesn't handle integer results
user name
2007-10-08 17:56:16
On Oct 08 2007, Jerry D. Hedden wrote:
> I'm really on a roll here.  I think I know how to fix
all of this
> stuff, but there are dozens of fuctions to tackle.  
Please disregard
> this patch (and the previous ones, too).  I'll work all
this out and
> submit one big patch that does it all.  Sorry for the
noise.

Thanks for taking this on.  I was going to do it but I'm
pretty slow
with stuff that doesn't affect me directly.

Please refactor the common stuff into a macro or function,
though.  And
we could use tests for these ops on plain ol' references,
too, since
they are also (I think) returning floats for 64bit when they
should
return ints.  I'm pretty sure the tests will be welcome
before the code
patch too.  If it's not too much trouble.  

P.S.  I think PTR2IV should be PTR2UV for the reference
case.

-- 
Rick Delaney
rickbort.ca

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )