[pure-lang-svn] SF.net SVN: pure-lang: [63] pure/trunk
Status: Beta
Brought to you by:
agraef
From: <ag...@us...> - 2008-05-06 17:01:12
|
Revision: 63 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=63&view=rev Author: agraef Date: 2008-05-06 10:01:15 -0700 (Tue, 06 May 2008) Log Message: ----------- Make pow work also with double arguments, add sqrt function. Modified Paths: -------------- pure/trunk/ChangeLog pure/trunk/lib/primitives.pure Modified: pure/trunk/ChangeLog =================================================================== --- pure/trunk/ChangeLog 2008-05-06 11:29:22 UTC (rev 62) +++ pure/trunk/ChangeLog 2008-05-06 17:01:15 UTC (rev 63) @@ -1,5 +1,9 @@ 2008-05-06 Albert Graef <Dr....@t-...> + * lib/primitives.pure: Made the pow function work with all + combinations of integer and double arguments. Added the sqrt + function. + * runtime.cc, lib/primitives.pure: Added predicates funp, lambdap, varp checking for named and anonymous closures and unbound global variables, respectively. Requested by Libor Spacek. Modified: pure/trunk/lib/primitives.pure =================================================================== --- pure/trunk/lib/primitives.pure 2008-05-06 11:29:22 UTC (rev 62) +++ pure/trunk/lib/primitives.pure 2008-05-06 17:01:15 UTC (rev 63) @@ -254,12 +254,35 @@ x::double==y::bigint = x==double y; x::double!=y::bigint = x!=double y; -extern expr* bigint_pow(void*, int); +/* The sqrt function. Integer arguments get promoted to double and the result + is always a double. The argument must be nonnegative. */ -pow x::bigint y::int = bigint_pow x y if y>=0; +extern double sqrt(double) = c_sqrt; + +sqrt x::int = c_sqrt (double x) if x>=0; +sqrt x::bigint = c_sqrt (double x) if x>=0; +sqrt x::double = c_sqrt x if x>=0; + +/* 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). */ + +extern expr* bigint_pow(void*, int), double pow(double, double) = c_pow; + pow x::int y::int = bigint_pow (bigint x) y if y>=0; pow x::bigint y::bigint = bigint_pow x (int y) if int y>=0; +pow x::double y::double = c_pow x y if x>=0 || int y==y; +// mixed int/bigint +pow x::int y::bigint = bigint_pow (bigint x) (int 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 = c_pow x (double y); +pow x::double y::bigint = c_pow x (double y); +pow x::int y::double = c_pow (double x) y if x>=0 || int y==y; +pow x::bigint y::double = c_pow (double x) y if x>=0 || int y==y; + /* Pointer arithmetic. We do this using bigints, so that the code is portable to 64 bit systems. */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |