Closed p5pRT closed 20 years ago
List::Util::sum returns questionable results when negative literals are provided on my Gentoo Linux AMD K6 800MHz box. It does not occur on my 1.6GHz Athlon\, no my Intel P-II Mobile. This occurs with 5.8.0 and 5.8.1-RC4:
[martyn:0]$ perl -MList::Util=sum -le 'print sum -1' 4294967295 [martyn:0]$ perl -MList::Util=sum -le 'print sum -1\, 2' 4294967297
this only occurs with literal values
[martyn:0]$ perl -MList::Util=sum -le 'print sum 0.0\, -12.0' -12 [martyn:0]$ perl -MList::Util=sum -le 'print sum "0"\, "-12"' -12 [martyn:0]$ perl -MList::Util=sum -le 'print sum 0+0\, -12+0' 4294967284 [martyn:0]$ perl -MList::Util=sum -le 'print sum 0*1\, -12*1' 4294967284 [martyn:0]$ perl -MList::Util=sum -le 'print sum @ARGV' 0 -12 -12 [martyn:0]$ perl -MList::Util=sum -le 'print sum -1\, 2' 4294967297
As the last line shows\, only one of the values has to be negative\, not necessarily the result.
It appears to be a signage issue:
[martyn:1]$ perl -le 'printf "%x\n"\, $_ for @ARGV' -- -12 4294967284 fffffff4 fffffff4
Beyond that\, as this is an XS issue\, I cannot delve. :-(
On 23 Sep 2003\, at 18:29\, martyn@chrome.sixears.co.uk (via RT) wrote:
List::Util::sum returns questionable results when negative literals are provided on my Gentoo Linux AMD K6 800MHz box. It does not occur on my 1.6GHz Athlon\, no my Intel P-II Mobile. This occurs with 5.8.0 and 5.8.1-RC4:
[martyn:0]$ perl -MList::Util=sum -le 'print sum -1' 4294967295
That is very odd
What do you get from
perl -MDevel::Peek -le 'Dump(-1)'
Graham.
On Tue\, Sep 23\, 2003 at 05:29:06PM -0000\, martyn@chrome.sixears.co.uk (via RT) wrote:
[martyn:0]$ perl -MList::Util=sum -le 'print sum -1' 4294967295
Various comments:
For me\, this doesn't happen in 5.8.0\, but happens in bleed. Change occured between 18020 and 18113.
When debugging\, the problem occurs in Util.xs around this line:
RETVAL = slu_sv_value(sv);
At this point\, sv is
SV = IV(0x818afc0) at 0x8189a2c REFCNT = 1 FLAGS = (IOK\,READONLY\,pIOK) IV = -1
slu_sv_value() is defined as:
define slu_sv_value(sv) (NV)(SvIOK(sv) ? SvIOK_UV(sv) ? SvUVX(sv) : SvIVX(sv) : SvNV(sv))
typeof(IV) is (long int)\, and typeof(RETVAL) is double.
Single-stepping at the machine instruction level shows that the IOK test succeeds and the SvIOK_UV test fails\, yet at the end of the assignment\, RETVAL is 4294967295\, not -1.
So I'm very confused.
-- Technology is dominated by two types of people: those who understand what they do not manage\, and those who manage what they do not understand.
On Wed\, 24 Sep 2003 00:12:50 +0100\, Dave Mitchell \davem@​fdgroup\.com said:
> RETVAL = slu_sv_value(sv);
That was introduced in patch 18076 and blame analysis indeed shows on my Athlon:
----Program---- use List::Util qw(sum); print sum -1;
----Output of .../prT8St3/perl-5.8.0@18075/bin/perl---- -1 ----EOF ($?='0')---- ----Output of .../pfZsvXT/perl-5.8.0@18076/bin/perl---- 1.84467440737096e+19 ----EOF ($?='0')----
-- andreas
On 24 Sep 2003\, at 9:33\, Martyn J. Pearce wrote:
On Tue\, Sep 23\, 2003 at 09:58:43PM +0100\, Graham Barr wrote:
On 23 Sep 2003\, at 18:29\, martyn@chrome.sixears.co.uk (via RT) wrote:
List::Util::sum returns questionable results when negative literals are provided on my Gentoo Linux AMD K6 800MHz box. It does not occur on my 1.6GHz Athlon\, no my Intel P-II Mobile. This occurs with 5.8.0 and 5.8.1-RC4:
I don't have time to test this fully today or do a release\, I have to run in 5 mins. But try this patch. If there are no reported problems then I will release tomorrow\, or maybe late tonight\, when I am back.
SvIVX(sv) : SvNV(sv)) +# define slu_sv_value(sv) (SvIOK(sv)) ? (SvIOK_UV(sv)) ? (NV)(SvUVX(sv)) : (NV)(SvIVX(sv)) : (SvNV(sv)) #else -# define slu_sv_value(sv) (NV)(SvIOK(sv) ? SvIVX(sv) : SvNV(sv)) +# define slu_sv_value(sv) (SvIOK(sv)) ? (NV)(SvIVX(sv)) : SvNV(sv) #endif
Graham.
On Tue\, Sep 23\, 2003 at 09:58:43PM +0100\, Graham Barr wrote:
On 23 Sep 2003\, at 18:29\, martyn@chrome.sixears.co.uk (via RT) wrote:
List::Util::sum returns questionable results when negative literals are provided on my Gentoo Linux AMD K6 800MHz box. It does not occur on my 1.6GHz Athlon\, no my Intel P-II Mobile. This occurs with 5.8.0 and 5.8.1-RC4:
[martyn:0]$ perl -MList::Util=sum -le 'print sum -1' 4294967295
That is very odd
What do you get from
perl -MDevel::Peek -le 'Dump(-1)'
Apologies for the delay: I'm on UK time\, and wrote the mail at the end of the day...
[martyn:0]$ perl -MDevel::Peek -le 'Dump(-1)']
SV = IV(0x8141c14) at 0x81338cc REFCNT = 1 FLAGS = (IOK\,READONLY\,pIOK) IV = -1
HTH\, Mx.
On Wed\, Sep 24\, 2003 at 09:55:21AM +0100\, Graham Barr wrote:
I don't have time to test this fully today or do a release\, I have to run in 5 mins. But try this patch. If there are no reported problems then I will release tomorrow\, or maybe late tonight\, when I am back.
Applied against 5.8.1-RC4\, this does the trick. Thank you very much for the quick response.
Mx.
On Wed\, Sep 24\, 2003 at 09:55:21AM +0100\, Graham Barr wrote:
I don't have time to test this fully today or do a release\, I have to run in 5 mins. But try this patch. If there are no reported problems then I will release tomorrow\, or maybe late tonight\, when I am back.
--- Util.xs.orig Wed Sep 24 08:35:19 2003 +++ Util.xs Wed Sep 24 08:34:29 2003 @@ -47\,9 +47\,9 @@ #endif
#ifdef SVf_IVisUV -# define slu_sv_value(sv) (NV)(SvIOK(sv) ? SvIOK_UV(sv) ? SvUVX(sv) : SvIVX(sv) : SvNV(sv)) +# define slu_sv_value(sv) (SvIOK(sv)) ? (SvIOK_UV(sv)) ? (NV)(SvUVX(sv)) : (NV)(SvIVX(sv)) : (SvNV(sv)) #else -# define slu_sv_value(sv) (NV)(SvIOK(sv) ? SvIVX(sv) : SvNV(sv)) +# define slu_sv_value(sv) (SvIOK(sv)) ? (NV)(SvIVX(sv)) : SvNV(sv) #endif
What goes wrong with using the direct output of SvNV(sv)? Certainly by 5.8.0 it should give identical results to
(SvIOK(sv)) ? (SvIOK_UV(sv)) ? (NV)(SvUVX(sv)) : (NV)(SvIVX(sv)) : (SvNV(sv))
Nicholas Clark
@iabyn - Status changed from 'new' to 'resolved'
Migrated from rt.perl.org#24012 (status was 'resolved')
Searchable as RT24012$