|
7 | 7 | * Portions Copyright (c) 1994, Regents of the University of California
|
8 | 8 | *
|
9 | 9 | * IDENTIFICATION
|
10 |
| - * $PostgreSQL: pgsql/src/backend/utils/adt/int8.c,v 1.66 2007/06/05 21:31:06 tgl Exp $ |
| 10 | + * $PostgreSQL: pgsql/src/backend/utils/adt/int8.c,v 1.67 2007/08/30 05:27:29 tgl Exp $ |
11 | 11 | *
|
12 | 12 | *-------------------------------------------------------------------------
|
13 | 13 | */
|
@@ -575,15 +575,19 @@ int8mul(PG_FUNCTION_ARGS)
|
575 | 575 | * Since the division is likely much more expensive than the actual
|
576 | 576 | * multiplication, we'd like to skip it where possible. The best bang for
|
577 | 577 | * the buck seems to be to check whether both inputs are in the int32
|
578 |
| - * range; if so, no overflow is possible. |
| 578 | + * range; if so, no overflow is possible. (But that only works if we |
| 579 | + * really have a 64-bit int64 datatype...) |
579 | 580 | */
|
580 |
| -if (!(arg1== (int64) ((int32)arg1)&& |
581 |
| -arg2== (int64) ((int32)arg2))&& |
582 |
| -arg2!=0&& |
583 |
| -(result /arg2!=arg1|| (arg2==-1&&arg1<0&&result<0))) |
584 |
| -ereport(ERROR, |
585 |
| -(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), |
586 |
| -errmsg("bigint out of range"))); |
| 581 | +#ifndefINT64_IS_BUSTED |
| 582 | +if (arg1!= (int64) ((int32)arg1)||arg2!= (int64) ((int32)arg2)) |
| 583 | +#endif |
| 584 | +{ |
| 585 | +if (arg2!=0&& |
| 586 | +(result /arg2!=arg1|| (arg2==-1&&arg1<0&&result<0))) |
| 587 | +ereport(ERROR, |
| 588 | +(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), |
| 589 | +errmsg("bigint out of range"))); |
| 590 | +} |
587 | 591 | PG_RETURN_INT64(result);
|
588 | 592 | }
|
589 | 593 |
|
|