Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Committers > Re: pgsql: Have...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 8 of 11 Topic 16074 of 18152
Post > Topic >>

Re: pgsql: Have numeric 0 ^ 4.3 return 1, rather

by bruce@[EMAIL PROTECTED] (Bruce Momjian) May 9, 2008 at 11:36 AM

--ELM1210347367-6657-0_
Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset="UNKNOWN-8BIT"

Tom Lane wrote:
> Simon Riggs <simon@[EMAIL PROTECTED]
> writes:
> > Wikipedia says that exponentiation of zero to a negative power implies
> > division by zero, so shouldn't we throw a "division by zero" error?
> 
> I think it should be a specific message like "zero raised to a negative
> power is undefined".  It's not like it's going to take us any extra code
> to know that we are faced with that case.
> 
> BTW, I realized that SQL:2003 spells it all out for us in explicit
> detail:

....

> b) If VB is 0 (zero) and VE is negative, then an exception condition is
> raised: data exception Ñ invalid argument for power function.

Well, this indicates we shouldn't return "zero raised to a negative
power is undefined", but rather the power error we are giving now, or
are you saying we should return the "power" error code but an error
message mentioning zero?

> c) If VB is 0 (zero) and VE is 0 (zero), then the result is 1 (one). 

I have updated the C comments to mention the spec also requires we
return 1 in this case.

C comment updated attached and applied.

-- 
  Bruce Momjian  <bruce@[EMAIL PROTECTED]
>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +

--ELM1210347367-6657-0_
Content-Transfer-Encoding: 7bit
Content-Type: text/x-diff
Content-Disposition: inline; filename="/rtmp/diff"

Index: src/backend/utils/adt/float.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/utils/adt/float.c,v
retrieving revision 1.155
diff -c -c -r1.155 float.c
*** src/backend/utils/adt/float.c	21 Apr 2008 00:26:45 -0000	1.155
--- src/backend/utils/adt/float.c	9 May 2008 15:34:53 -0000
***************
*** 1331,1337 ****
  
  	/*
  	 * The SQL spec requires that we emit a particular SQLSTATE error code
for
! 	 * certain error conditions.
  	 */
  	if ((arg1 == 0 && arg2 < 0) ||
  		(arg1 < 0 && floor(arg2) != arg2))
--- 1331,1338 ----
  
  	/*
  	 * The SQL spec requires that we emit a particular SQLSTATE error code
for
! 	 * certain error conditions.  Specifically, we don't return a
divide-by-zero
! 	 * error code for 0 ^ -1.
  	 */
  	if ((arg1 == 0 && arg2 < 0) ||
  		(arg1 < 0 && floor(arg2) != arg2))
Index: src/backend/utils/adt/numeric.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v
retrieving revision 1.112
diff -c -c -r1.112 numeric.c
*** src/backend/utils/adt/numeric.c	8 May 2008 22:17:54 -0000	1.112
--- src/backend/utils/adt/numeric.c	9 May 2008 15:34:53 -0000
***************
*** 1893,1900 ****
  	trunc_var(&arg2_trunc, 0);
  
  	/*
! 	 * Return special SQLSTATE error codes for a few conditions mandated by
! 	 * the standard.
  	 */
  	if ((cmp_var(&arg1, &const_zero) == 0 &&
  		 cmp_var(&arg2, &const_zero) < 0) ||
--- 1893,1901 ----
  	trunc_var(&arg2_trunc, 0);
  
  	/*
! 	 * The SQL spec requires that we emit a particular SQLSTATE error code
for
! 	 * certain error conditions.  Specifically, we don't return a
divide-by-zero
! 	 * error code for 0 ^ -1.
  	 */
  	if ((cmp_var(&arg1, &const_zero) == 0 &&
  		 cmp_var(&arg2, &const_zero) < 0) ||
***************
*** 5283,5288 ****
--- 5284,5290 ----
  			/*
  			 *	While 0 ^ 0 can be either 1 or indeterminate (error), we
  			 *	treat it as 1 because most programming languages do this.
+ 			 *	SQL:2003 also requires a return value of 1.
  			 *	http://en.wikipedia.org/wiki/Exponentiation#Zero_to_the_zero_power
  			 */
  			set_var_from_var(&const_one, result);

--ELM1210347367-6657-0_
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
MIME-Version: 1.0


-- 
Sent via pgsql-committers mailing list (pgsql-committers@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers

--ELM1210347367-6657-0_--
 




 11 Posts in Topic:
pgsql: Have numeric 0 ^ 4.3 return 1, rather than an error, and
momjian@[EMAIL PROTECTED]  2008-05-08 19:25:38 
Re: pgsql: Have numeric 0 ^ 4.3 return 1, rather than
neilc@[EMAIL PROTECTED]   2008-05-08 14:00:35 
Re: pgsql: Have numeric 0 ^ 4.3 return 1, rather
bruce@[EMAIL PROTECTED]   2008-05-08 18:18:00 
Re: pgsql: Have numeric 0 ^ 4.3 return 1, rather than an error,
tgl@[EMAIL PROTECTED] (T  2008-05-08 18:23:31 
Re: pgsql: Have numeric 0 ^ 4.3 return 1, rather
bruce@[EMAIL PROTECTED]   2008-05-08 18:34:20 
Re: pgsql: Have numeric 0 ^ 4.3 return 1, rather than
simon@[EMAIL PROTECTED]   2008-05-09 09:00:36 
Re: pgsql: Have numeric 0 ^ 4.3 return 1, rather than an error,
tgl@[EMAIL PROTECTED] (T  2008-05-09 10:37:07 
Re: pgsql: Have numeric 0 ^ 4.3 return 1, rather
bruce@[EMAIL PROTECTED]   2008-05-09 11:36:07 
Re: pgsql: Have numeric 0 ^ 4.3 return 1, rather than an error,
tgl@[EMAIL PROTECTED] (T  2008-05-09 11:57:42 
Re: pgsql: Have numeric 0 ^ 4.3 return 1, rather
bruce@[EMAIL PROTECTED]   2008-05-09 11:58:41 
Re: pgsql: Have numeric 0 ^ 4.3 return 1, rather
bruce@[EMAIL PROTECTED]   2008-05-09 17:32:26 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Dec 2 0:17:27 CST 2008.