fractional part of a number

Discussion of Common Lisp
Post Reply
stackman
Posts: 28
Joined: Sat Oct 06, 2012 5:44 am

fractional part of a number

Post by stackman » Mon Oct 15, 2012 1:35 pm

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.

Goheeca
Posts: 271
Joined: Thu May 10, 2012 12:54 pm
Contact:

Re: fractional part of a number

Post by Goheeca » Mon Oct 15, 2012 2:19 pm

Have a look at mod & rem.

Code: Select all

(mod 1.5 1)
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.

Paul
Posts: 106
Joined: Tue Jun 02, 2009 6:00 am

Re: fractional part of a number

Post by Paul » Mon Oct 15, 2012 2:30 pm

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))

stackman
Posts: 28
Joined: Sat Oct 06, 2012 5:44 am

Re: fractional part of a number

Post by stackman » Thu Oct 18, 2012 1:01 am

Thanks for the replies, this is definitely better.

Post Reply