[gambit-list] Any rational-number->string with infinite precision for decimal output? (i.e. d.ddddd rather than x/y)
Marc Feeley
feeley at iro.umontreal.ca
Thu Jan 16 08:58:00 EST 2014
On Jan 16, 2014, at 8:35 AM, Hendrik Boom <hendrik at topoi.pooq.com> wrote:
> If all you want is a boolean, maybe it would be simpler to reduce the
> fraction to lowest terms (might this already have been done?) and then
> checking if the denominator is divisible by 2 or 5.
I guess you mean that 2 and 5 are the only factors (for example 1/140 has an infinite decimal representation but the denominator is divisible by 2, 5 and 7).
Marc
(define (has-finite-decimal-representation? n) ;; n is a positive real
(define (remove-factor factor n)
(if (zero? (modulo n factor))
(remove-factor factor (quotient n factor))
n))
(= 1 (remove-factor 2 (remove-factor 5 (denominator (inexact->exact n))))))
More information about the Gambit-list
mailing list