On Tue, Jul 12, 2016 at 1:51 PM, David Kastrup [via Lilypond] <
ml-node+s1069038n192627...@n5.nabble.com> wrote:

> Abraham Lee <[hidden email]
> <http:///user/SendEmail.jtp?type=node&node=192627&i=0>> writes:
>
> > Does anyone have a solution for the occasional HUGE integers that can be
> > created for the numerator/denominator when using inexact->exact?
> >
> > For example,
> >
> > (inexact->exact 0.2)
> >
> > yields
> >
> > 3602879701896400/18014398509482000
> >
> > It is correct, but LP doesn't seem to want to deal with such large
> > integers, at least for me.
>
> That should get fixed at some point of time: LilyPond's rational numbers
> precede Guile's but nowadays maintaining them is a nuisance.
>

Good to know.


> > Can this be reduced to 1/5 somehow? Is there a better way to get a
> > rational from a decimal? I can write a crazy function that
> > procedurally determines the minimum power of 10 that gives me a
> > rational with smaller numbers, but I'd rather not. Any advice is very
> > welcome.
>
> guile> (rationalize (inexact->exact 0.2) 1/10000)
> 1/5
> guile> (help rationalize)
> `rationalize' is a primitive procedure in the (guile) module.
>
> -- Scheme Procedure: rationalize x eps
>      Returns the _simplest_ rational number differing from X by no more
>      than EPS.
>
>      As required by R5RS, 'rationalize' only returns an exact result
>      when both its arguments are exact.  Thus, you might need to use
>      'inexact->exact' on the arguments.
>
>           (rationalize (inexact->exact 1.2) 1/100)
>           => 6/5
>

Brilliant! I was trying to figure out how to make that function work,
thinking it would be what I needed, and those two examples were perfect in
helping me understand how to use it effectively. I'm back on the road
again! Thank you, David!

--
Abraham Lee




--
View this message in context: 
http://lilypond.1069038.n5.nabble.com/Scheme-conversion-inexact-exact-question-tp192624p192628.html
Sent from the User mailing list archive at Nabble.com.
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to