[pure-lang-svn] SF.net SVN: pure-lang:[492] pure/trunk/lib/math.pure
Status: Beta
Brought to you by:
agraef
From: <ag...@us...> - 2008-08-14 12:22:44
|
Revision: 492 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=492&view=rev Author: agraef Date: 2008-08-14 12:22:54 +0000 (Thu, 14 Aug 2008) Log Message: ----------- Overhaul of number predicates. Modified Paths: -------------- pure/trunk/lib/math.pure Modified: pure/trunk/lib/math.pure =================================================================== --- pure/trunk/lib/math.pure 2008-08-14 07:59:36 UTC (rev 491) +++ pure/trunk/lib/math.pure 2008-08-14 12:22:54 UTC (rev 492) @@ -563,13 +563,33 @@ /* Additional number predicates. */ complexp x = case x of x+:y | x<:y = realp x && realp y; _ = 0 end; -rationalp x = case x of x%y = bigintp x && bigintp y; _ = 0 end; -realp x = intp x || bigintp x || doublep x || rationalp x; +realp x = case x of _::int | _::bigint | _::double | + _::bigint%_::bigint = 1; _ = 0 end; +rationalp x = case x of _::bigint%_::bigint = 1; _ = 0 end; numberp x = realp x || complexp x; -inexactp x = doublep x || doublep (re x) || doublep (im x) if numberp x; -exactp x = not(doublep x || doublep (re x) || doublep (im x)) - if numberp x; +/* Semantic number predicates. In difference to the syntactic predicates in + primitives.pure and above, these check whether the given value can be + represented as an object of the given target type (up to rounding + errors). Note that if x is of syntactic type X, then it is also of semantic + type X. Moreover, intvalp x => bigintvalp x => ratvalp x => realvalp x => + compvalp x <=> numberp x. */ -infp x::double = not nanp x && nanp (x-x); -nanp x::double = x===nan; +compvalp x = numberp x; +realvalp x = compvalp x && im x==0; +ratvalp x = realvalp x && (y-y!==nan when y = re x end); +bigintvalp x = ratvalp x && den x==1; +intvalp x = bigintvalp && int x==x; + +/* Check whether a number is exact (i.e., doesn't contain any double + components. */ + +exactp x = numberp x && + not (doublep x || doublep (re x) || doublep (im x)); +inexactp x = numberp x && + (doublep x || doublep (re x) || doublep (im x)); + +/* Check for inf and nan values. */ + +infp x = case x of x::double = x!==nan && x-x===nan; _ = 0 end; +nanp x = case x of x::double = x===nan; _ = 0 end; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |