[pure-lang-svn] SF.net SVN: pure-lang: [357] pure/trunk
Status: Beta
Brought to you by:
agraef
From: <ag...@us...> - 2008-07-01 21:53:01
|
Revision: 357 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=357&view=rev Author: agraef Date: 2008-07-01 14:53:10 -0700 (Tue, 01 Jul 2008) Log Message: ----------- Add GMP gcd and lcm functions. Modified Paths: -------------- pure/trunk/ChangeLog pure/trunk/lib/primitives.pure pure/trunk/runtime.cc pure/trunk/runtime.h Modified: pure/trunk/ChangeLog =================================================================== --- pure/trunk/ChangeLog 2008-07-01 21:04:46 UTC (rev 356) +++ pure/trunk/ChangeLog 2008-07-01 21:53:10 UTC (rev 357) @@ -1,5 +1,8 @@ 2008-07-01 Albert Graef <Dr....@t-...> + * lib/primitives.pure, runtime.cc/h: Add the GMP gcd and lcm + functions. + * lexer.ll: 'list' command now also prints fixity and nullary declarations of listed symbols. Modified: pure/trunk/lib/primitives.pure =================================================================== --- pure/trunk/lib/primitives.pure 2008-07-01 21:04:46 UTC (rev 356) +++ pure/trunk/lib/primitives.pure 2008-07-01 21:53:10 UTC (rev 357) @@ -267,6 +267,23 @@ x::double==y::bigint = x==double y; x::double!=y::bigint = x!=double y; +/* The gcd and lcm functions from the GMP library. These return a bigint if at + least one of the arguments is a bigint, a machine int otherwise. */ + +extern expr* bigint_gcd(void*, void*); +extern expr* bigint_lcm(void*, void*); + +gcd x::bigint y::bigint = bigint_gcd x y; +lcm x::bigint y::bigint = bigint_lcm x y; + +gcd x::int y::bigint = bigint_gcd (bigint x) y; +gcd x::bigint y::int = bigint_gcd x (bigint y); +gcd x::int y::int = int (bigint_gcd (bigint x) (bigint y)); + +lcm x::int y::bigint = bigint_lcm (bigint x) y; +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). */ Modified: pure/trunk/runtime.cc =================================================================== --- pure/trunk/runtime.cc 2008-07-01 21:04:46 UTC (rev 356) +++ pure/trunk/runtime.cc 2008-07-01 21:53:10 UTC (rev 357) @@ -1894,6 +1894,24 @@ } extern "C" +pure_expr *bigint_gcd(mpz_t x, mpz_t y) +{ + pure_expr *u = pure_bigint(0, 0); + mpz_t& z = u->data.z; + mpz_gcd(z, x, y); + return u; +} + +extern "C" +pure_expr *bigint_lcm(mpz_t x, mpz_t y) +{ + pure_expr *u = pure_bigint(0, 0); + mpz_t& z = u->data.z; + mpz_lcm(z, x, y); + return u; +} + +extern "C" int32_t bigint_cmp(mpz_t x, mpz_t y) { return mpz_cmp(x, y); Modified: pure/trunk/runtime.h =================================================================== --- pure/trunk/runtime.h 2008-07-01 21:04:46 UTC (rev 356) +++ pure/trunk/runtime.h 2008-07-01 21:53:10 UTC (rev 357) @@ -443,6 +443,9 @@ pure_expr *bigint_and(mpz_t x, mpz_t y); pure_expr *bigint_or(mpz_t x, mpz_t y); +pure_expr *bigint_gcd(mpz_t x, mpz_t y); +pure_expr *bigint_lcm(mpz_t x, mpz_t y); + int32_t bigint_cmp(mpz_t x, mpz_t y); /* String operations. In difference to the string operations from the C This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |