[racket] Rationalize & denominator: is it bug?

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Thu Jun 26 02:23:38 EDT 2014

At Thu, 26 Jun 2014 10:15:30 +0400, Roman Klochkov wrote:
>  > (denominator (rationalize (/ 23 10) 0.01))
> 1125899906842624.0
> 
> > (denominator (/ 23 10))
> 10 From refernece for rationalize:
> Among the real numbers within (abs tolerance) of x, returns the one 
> corresponding to an exact number whose denominator is the smallest.
> 
> I expect to have 10 from (denominator (rationalize (/ 23 10) 0.01))

Thats what you'd get from

 (denominator (rationalize (/ 23 10) 1/100))

but 0.01 is an inexact number, which causes `rationalize` to produce an
inexact result. The inexact result is an approximation of 2.3, instead
of 23/10, and the denominator of the approximation of 2.3 isn't 10.



Posted on the users mailing list.