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 3 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 8, 2008 at 06:18 PM

--ELM1210285080-15523-0_
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset="US-ASCII"

Neil Conway wrote:
> On Thu, 2008-05-08 at 19:25 +0000, Bruce Momjian wrote:
> > Have numeric 0 ^ 4.3 return 1, rather than an error, and have 0 ^ 0.0
> > return 1, rather than error.
> 
> A regression test for this behavior would be useful, I think.

Done, plus I wasn't happy with the original patch so I redid it to be
more modular, also attached.

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

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

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

Index: src/backend/utils/adt/numeric.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v
retrieving revision 1.111
diff -c -c -r1.111 numeric.c
*** src/backend/utils/adt/numeric.c	8 May 2008 19:25:38 -0000	1.111
--- src/backend/utils/adt/numeric.c	8 May 2008 22:16:55 -0000
***************
*** 5170,5190 ****
  	int			local_rscale;
  	double		val;
  
- 	/*
- 	 *	This avoids log(0) for cases of 0 raised to a non-integer.
- 	 *	Also, while 0 ^ 0 can be either 1 or indeterminate (error), we
- 	 *	treat it as one because most programming languages do this.
- 	 *	http://en.wikipedia.org/wiki/Exponentiation#Zero_to_the_zero_power
- 	 */
- 	if (cmp_var(base, &const_zero) == 0)
- 	{
- 		if (cmp_var(exp, &const_zero) == 0)
- 			set_var_from_var(&const_one, result);
- 		else
- 			set_var_from_var(&const_zero, result);
- 		return;
- 	}
- 	
  	/* If exp can be represented as an integer, use power_var_int */
  	if (exp->ndigits == 0 || exp->ndigits <= exp->weight + 1)
  	{
--- 5170,5175 ----
***************
*** 5217,5222 ****
--- 5202,5218 ----
  		free_var(&x);
  	}
  
+ 	/*
+ 	 *	This avoids log(0) for cases of 0 raised to a non-integer.
+ 	 *	0 ^ 0 handled by power_var_int().
+ 	 */
+ 	if (cmp_var(base, &const_zero) == 0)
+ 	{
+ 		set_var_from_var(&const_zero, result);
+ 		result->dscale = NUMERIC_MIN_SIG_DIGITS;	/* no need to round */
+ 		return;
+ 	}
+ 	
  	init_var(&ln_base);
  	init_var(&ln_num);
  
***************
*** 5284,5289 ****
--- 5280,5290 ----
  	switch (exp)
  	{
  		case 0:
+ 			/*
+ 			 *	While 0 ^ 0 can be either 1 or indeterminate (error), we
+ 			 *	treat it as 1 because most programming languages do this.
+ 			 *	http://en.wikipedia.org/wiki/Exponentiation#Zero_to_the_zero_power
+ 			 */
  			set_var_from_var(&const_one, result);
  			result->dscale = rscale;	/* no need to round */
  			return;
Index: src/test/regress/expected/float8.out
===================================================================
RCS file: /cvsroot/pgsql/src/test/regress/expected/float8.out,v
retrieving revision 1.25
diff -c -c -r1.25 float8.out
*** src/test/regress/expected/float8.out	2 Jan 2007 20:00:50 -0000	1.25
--- src/test/regress/expected/float8.out	8 May 2008 22:16:56 -0000
***************
*** 349,354 ****
--- 349,360 ----
  ERROR:  value out of range: overflow
  SELECT '' AS bad, f.f1 ^ '1e200' from FLOAT8_TBL f;
  ERROR:  value out of range: overflow
+ SELECT 0 ^ 0 + 0 ^ 1 + 0 ^ 0.0 + 0 ^ 0.5;
+  ?column? 
+ ----------
+         2
+ (1 row)
+ 
  SELECT '' AS bad, ln(f.f1) from FLOAT8_TBL f where f.f1 = '0.0' ;
  ERROR:  cannot take logarithm of zero
  SELECT '' AS bad, ln(f.f1) from FLOAT8_TBL f where f.f1 < '0.0' ;
Index: src/test/regress/sql/float8.sql
===================================================================
RCS file: /cvsroot/pgsql/src/test/regress/sql/float8.sql,v
retrieving revision 1.15
diff -c -c -r1.15 float8.sql
*** src/test/regress/sql/float8.sql	8 Jun 2005 21:15:29 -0000	1.15
--- src/test/regress/sql/float8.sql	8 May 2008 22:16:56 -0000
***************
*** 129,134 ****
--- 129,136 ----
  
  SELECT '' AS bad, f.f1 ^ '1e200' from FLOAT8_TBL f;
  
+ SELECT 0 ^ 0 + 0 ^ 1 + 0 ^ 0.0 + 0 ^ 0.5;
+ 
  SELECT '' AS bad, ln(f.f1) from FLOAT8_TBL f where f.f1 = '0.0' ;
  
  SELECT '' AS bad, ln(f.f1) from FLOAT8_TBL f where f.f1 < '0.0' ;

--ELM1210285080-15523-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

--ELM1210285080-15523-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 1:01:47 CST 2008.