[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: guile-question: 3/2 -> "1 1/2"
From: |
Andrew Bernard |
Subject: |
Re: guile-question: 3/2 -> "1 1/2" |
Date: |
Wed, 12 Aug 2015 20:28:58 +1000 |
User-agent: |
Microsoft-MacOutlook/0.0.0.150724 |
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.