2015-08-12 12:28 GMT+02:00 Andrew Bernard <[email protected]>: > Hi Harm, > > > > User specification of input only guessed at by me. :-) > > Of course, for negative and positive input (e.g. -3/2): > > (define (mixed-num x) > (let* ((n (numerator x)) > (d (denominator x))) > (cons (truncate (/ n d)) (abs (/ (remainder n d) d))))) > > But are you saying you also need the function to take any number as input, > not just a known fraction? Do you really want something like the rationalize > function ? The common mathematical term for 3 1/2 is mixed number, or mixed > fraction, by the way. > > > > Andrew > > > On 12/08/2015 09:09, "Thomas Morley" > <[email protected] on behalf of > [email protected]> wrote: > >> >>`mixed-num' can't deal with negative input right now, returning wrong >>(could be fixed ofcourse). >> >>In case the input is not exact `mixed-num' crashes, whereas >>`integer-and-fraction' doesn't, although returning not a fraction. >
Hi Andrew, converting 3/2 -> 1½ is ofcourse a helper-function for some larger project. Because I'm not entirely sure the input will always positive and exact, I tested what happens. I'll add that exact?-condition (already mentioned) and/or I'll make sure the input will always be exact. Thanks again for your input, it's highly appreciated! Cheers, Harm _______________________________________________ lilypond-user mailing list [email protected] https://lists.gnu.org/mailman/listinfo/lilypond-user
