[pure-lang-svn] SF.net SVN: pure-lang: [363] pure/trunk/lib/math.pure
Status: Beta
Brought to you by:
agraef
From: <ag...@us...> - 2008-07-02 08:01:28
|
Revision: 363 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=363&view=rev Author: agraef Date: 2008-07-02 01:01:36 -0700 (Wed, 02 Jul 2008) Log Message: ----------- Add missing rules. Modified Paths: -------------- pure/trunk/lib/math.pure Modified: pure/trunk/lib/math.pure =================================================================== --- pure/trunk/lib/math.pure 2008-07-02 01:13:39 UTC (rev 362) +++ pure/trunk/lib/math.pure 2008-07-02 08:01:36 UTC (rev 363) @@ -449,6 +449,12 @@ num (x%y) = x; den (x%y) = y; +num x::int | +num x::bigint = x; + +den x::int | +den x::bigint = 1; + /* Absolute value and sign. */ abs (x%y) = abs x % y; @@ -458,6 +464,9 @@ floor x@(_%_) = if n<=x then n else n-1 when n::bigint = trunc x end; ceil x@(_%_) = -floor (-x); +round (x%y) = -round ((-x)%y) if x<0; + = x div 2 + 1 if y==2; + = (2*x+y) div (2*y) otherwise; trunc (x%y) = x div y; frac x@(_%_) = x-trunc x; @@ -470,6 +479,12 @@ pow (x%y) n::double = pow (x/y) n; pow (x%y) (n%m) = pow (x/y) (n/m); +// Negative powers of integers. +pow x::int n::int | +pow x::int n::bigint | +pow x::bigint n::int | +pow x::bigint n::bigint = 1 % pow x (-n) if n<0; + /* Fallback rules for other functions (inexact results). */ sqrt (x%y) = sqrt (x/y); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |