lilypond-user
[Top][All Lists]
Advanced

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

Re: guile-question: 3/2 -> "1 1/2"


From: Thomas Morley
Subject: Re: guile-question: 3/2 -> "1 1/2"
Date: Thu, 13 Aug 2015 21:59:47 +0200

2015-08-12 12:28 GMT+02:00 Andrew Bernard <address@hidden>:
> 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" <address@hidden on behalf of 
> address@hidden> 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]