Re: Bug in numeric multiplication - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Bug in numeric multiplication
Date
Msg-id 6087.1448474244@sss.pgh.pa.us
Whole thread Raw
In response to Re: Bug in numeric multiplication  (Dean Rasheed <dean.a.rasheed@gmail.com>)
List pgsql-hackers
Dean Rasheed <dean.a.rasheed@gmail.com> writes:
> On 24 November 2015 at 16:20, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> ... None of these effects are going to let the final div[qi+1] value
>> get to more than two or three times NBASE squared, which is still
>> an order of magnitude less than INT_MAX.

> Right. In fact I think div[qi+1] is even more constrained than that (see below).

Thanks for the additional analysis and testing.

>> I think all this deserves some code comments, but I'm not sure whether
>> we need to bother with casting to int64.  Thoughts?

> I think probably just a comment is OK.

I'm inclined to agree.  The only reason I'd worry at all is that the
compiler guys are getting ever more aggressive about claiming that any
integer overflow can result in arbitrarily-broken behavior.  However,
we already have a lot of other code that depends on -fwrapv or equivalent
overflow behavior, so I doubt that this is the first place to worry
about it.  The underlying hardware is certainly going to behave as we
wish, and it's pretty hard to see how a compiler could "optimize" the
assembly code in a way that would break such a simple calculation.

I'll go add some comments and call it good.
        regards, tom lane



pgsql-hackers by date:

Previous
From: Greg Stark
Date:
Subject: Re: New email address
Next
From: Tom Lane
Date:
Subject: Re: New email address