Re: BUG #15519: Casting float4 into int4 gets the wrong sign instead of "integer out of range" error
От | Tom Lane |
---|---|
Тема | Re: BUG #15519: Casting float4 into int4 gets the wrong sign instead of "integer out of range" error |
Дата | |
Msg-id | 18151.1543023756@sss.pgh.pa.us обсуждение исходный текст |
Ответ на | BUG #15519: Casting float4 into int4 gets the wrong sign instead of"integer out of range" error (PG Bug reporting form <noreply@postgresql.org>) |
Ответы |
Re: BUG #15519: Casting float4 into int4 gets the wrong sign insteadof "integer out of range" error
|
Список | pgsql-bugs |
Victor Petrovykh <victor@magic.io> writes: > Am I missing something in thinking that the cast of a float to int should > produce an error if the sign of the original value doesn't match the sign > of the cast result? Well, yeah, our traditional way of coding this overflow check would probably have compared the sign of the result to the sign of the input, but (a) we'd still have needed some ad-hoc range check to avoid getting fooled by inputs large enough to have wrapped around an even number of times, and (b) this approach depends on the compiler not taking any liberties based on an assumption that the program doesn't provoke integer overflow. (b) gets more worrisome with each year that goes by, because the compiler guys keep finding ever-more-creative ways to break your code if it violates C-spec semantics. So we really want to write a test that will fail exactly when the integer coercion would overflow, not do the coercion and then check to see if it overflowed. regards, tom lane
В списке pgsql-bugs по дате отправления: