Page 1 of 1

fractional part of a number

Posted: Mon Oct 15, 2012 1:35 pm
by stackman
Hi,
Is there a simple way to return the fractional part of a number in common lisp?
At the moment I am using

Code: Select all

(multiple-value-call (lambda (x y)(declare (ignore x)) y) (floor 1.5))
but this seems a bit verbose.

Re: fractional part of a number

Posted: Mon Oct 15, 2012 2:19 pm
by Goheeca
Have a look at mod & rem.

Code: Select all

(mod 1.5 1)

Re: fractional part of a number

Posted: Mon Oct 15, 2012 2:30 pm
by Paul
stackman wrote:Hi,
Is there a simple way to return the fractional part of a number in common lisp?
At the moment I am using

Code: Select all

(multiple-value-call (lambda (x y)(declare (ignore x)) y) (floor 1.5))
but this seems a bit verbose.
FWIW, (nth-value 1 (floor 1.5))

Re: fractional part of a number

Posted: Thu Oct 18, 2012 1:01 am
by stackman
Thanks for the replies, this is definitely better.