[pure-lang-svn] SF.net SVN: pure-lang:[561] pure/trunk/lib
Status: Beta
Brought to you by:
agraef
From: <ag...@us...> - 2008-08-22 00:03:35
|
Revision: 561 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=561&view=rev Author: agraef Date: 2008-08-22 00:03:45 +0000 (Fri, 22 Aug 2008) Log Message: ----------- Revert pow to its original definition which computes exact (integer or rational) powers for integer exponents only. Modified Paths: -------------- pure/trunk/lib/math.pure pure/trunk/lib/primitives.pure Modified: pure/trunk/lib/math.pure =================================================================== --- pure/trunk/lib/math.pure 2008-08-21 22:47:08 UTC (rev 560) +++ pure/trunk/lib/math.pure 2008-08-22 00:03:45 UTC (rev 561) @@ -461,17 +461,13 @@ trunc (x%y) = x div y; frac x@(_%_) = x-trunc x; -/* The pow function. Returns exact results for integer exponents. */ +/* The pow function. Returns exact powers of integers and rationals for all + integer exponents. */ pow (x%y) n::int | pow (x%y) n::bigint = pow x n % pow y n if n>0; = pow y (-n) % pow x (-n) if n<0; = 1L%1L otherwise; -pow (x%y) n::double = pow (x/y) n; -pow (x%y) (n%m) = pow (x/y) (n/m); -pow x::int (n%m) | -pow x::bigint (n%m) | -pow x::double (n%m) = pow x (n/m); // Negative powers of integers. pow x::int n::int | Modified: pure/trunk/lib/primitives.pure =================================================================== --- pure/trunk/lib/primitives.pure 2008-08-21 22:47:08 UTC (rev 560) +++ pure/trunk/lib/primitives.pure 2008-08-22 00:03:45 UTC (rev 561) @@ -336,28 +336,25 @@ lcm x::bigint y::int = bigint_lcm x (bigint y); lcm x::int y::int = int (bigint_lcm (bigint x) (bigint y)); -/* The pow function. Returns a bigint for integer arguments, double if one of - the arguments is double (in the latter case, x may be negative only if y is - integer). */ +/* The pow function. Computes exact powers of ints and bigints. The result is + always a bigint. Note that y must always be nonnegative here, but see + math.pure which deals with the case y<0 using rational numbers. */ -extern expr* bigint_pow(void*, int), double pow(double, double) = c_pow; +extern expr* bigint_pow(void*, int); pow x::int y::int = bigint_pow (bigint x) y if y>=0; pow x::bigint y::bigint = bigint_pow x y if y>=0; -pow x::double y::double = c_pow x y if x>=0 || frac y==0.0; // mixed int/bigint pow x::int y::bigint = bigint_pow (bigint x) y if y>=0; pow x::bigint y::int = bigint_pow x y if y>=0; -// mixed double/int/bigint -pow x::double y::int | -pow x::double y::bigint = c_pow x (double y); -pow x::int y::double | -pow x::bigint y::double = c_pow (double x) y if x>=0 || frac y==0.0; +/* The ^ operator. Computes inexact powers for any combination of int, bigint + and double operands. The result is always a double. Note that x may be + negative only if y is integer, but see math.pure which deals with the + general case x<0 using complex numbers. */ -/* The ^ operator. Works like pow, but always promotes its operands to double - and returns a double result. */ +extern double pow(double, double) = c_pow; x::double^y::double = c_pow x y if x>=0 || frac y==0.0 || nanp x || nanp y; x::int^y::int | This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |