Re: question about the function 'round' in rep



On Tuesday 01 September 2009 21:19:37 Nathan Froyd wrote:
> It's quite confusing for INTEGERP to return T for (ROUND 2.3), but
> have MOVE-WINDOW-TO--which presumably expects integers--to complain
> about being given the result of (ROUND 2.3).

Integerp returns whether the result is a number with an integer value.  
It does not test the type of numeric representation.  Use inexactp to 
test for inexact representation, i.e., floating point, or exactp to test 
for exact representation, i.e., integer type or rational.

In general numerical functions, including floor, ceiling, truncate and 
round, return inexact results if any of the arguments are inexact, so 
(round 2.3) returns an inexact 2 while (round 23/10) returns an exact 2.  
And (round 1e+42) return 1e+42 regardless of bignum support.

If you think that was confusing, try (rationalp (sqrt 2)).  The 
explanation is that rationalp, like integerp, tests value rather than 
representation and Rep, like most programming languages, is not able to 
represent irrational numbers.  Hence rationalp and realp are synonyms 
(to numberp, because Rep does not have complex numbers).

This is essentially as in R5RS except that inexact->exact is broken.

-- 
	Timo Korvola		<URL:http://www.iki.fi/tkorvola>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]