fractional part of a number

Discussion of Common Lisp

fractional part of a number

Postby 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.
stackman
 
Posts: 28
Joined: Sat Oct 06, 2012 5:44 am

Re: fractional part of a number

Postby 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).
User avatar
Goheeca
 
Posts: 213
Joined: Thu May 10, 2012 12:54 pm

Re: fractional part of a number

Postby 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))
Paul
 
Posts: 106
Joined: Tue Jun 02, 2009 6:00 am

Re: fractional part of a number

Postby stackman » Thu Oct 18, 2012 1:01 am

Thanks for the replies, this is definitely better.
stackman
 
Posts: 28
Joined: Sat Oct 06, 2012 5:44 am


Return to Common Lisp

Who is online

Users browsing this forum: No registered users and 4 guests

cron