[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

which idiom is better for obtaining the fractional part of a number in Common Lisp

kodifik

1/17/2016 8:00:00 AM

(rem number 1) is less verbose, but maybe (nth-value 1 (truncate number)) is more efficient.
What do you use ?
Thanks.
16 Answers

Teemu Likonen

1/17/2016 8:27:00 AM

0

kodifik@gmail.com [2016-01-17 00:00:24-08] wrote:

> (rem number 1) is less verbose, but maybe (nth-value 1 (truncate
> number)) is more efficient. What do you use ?

Doesn't matter. It's very likely that they'll produce the same code. Use
DISASSEMBLE function to inspect the low-level code more closely.

--
/// Teemu Likonen - .-.. <https://github.com/tl... //
// PGP: 4E10 55DC 84E9 DFF6 13D7 8557 719D 69D3 2453 9450 ///

Kaz Kylheku

1/17/2016 5:13:00 PM

0

On 2016-01-17, kodifik@gmail.com <kodifik@gmail.com> wrote:
> (rem number 1) is less verbose, but maybe (nth-value 1 (truncate number)) is more efficient.
> What do you use ?

That depends. Do you want the fractional part of -3.2 to be -0.2,
or do you regard it as being 0.8?

Paul Rubin

1/17/2016 8:33:00 PM

0

kodifik@gmail.com writes:
> (rem number 1) is less verbose, but maybe (nth-value 1 (truncate
> number)) is more efficient. What do you use ?

I thought (truncate number 1) or (floor number 1) were the standard
ways, depending on what result you want if number is negative.

Barry Margolin

1/17/2016 9:23:00 PM

0

In article <87wpr8vtel.fsf@nightsong.com>,
Paul Rubin <no.email@nospam.invalid> wrote:

> kodifik@gmail.com writes:
> > (rem number 1) is less verbose, but maybe (nth-value 1 (truncate
> > number)) is more efficient. What do you use ?
>
> I thought (truncate number 1) or (floor number 1) were the standard
> ways, depending on what result you want if number is negative.

Those return the integer part, not the fraction.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

Paul Rubin

1/17/2016 11:09:00 PM

0

Barry Margolin <barmar@alum.mit.edu> writes:
>> I thought (truncate number 1) or (floor number 1) were the standard
>> ways, depending on what result you want if number is negative.
> Those return the integer part, not the fraction.

Hmm. You do get both parts,

Welcome to GNU CLISP 2.49+ (2010-07-17) <http://clis...
[1]> (floor 1.234 1)
1 ;
0.23399997

but I'm not sure how to get just the fraction part cleanly.

Pascal J. Bourguignon

1/18/2016 12:10:00 AM

0

Paul Rubin <no.email@nospam.invalid> writes:

> Barry Margolin <barmar@alum.mit.edu> writes:
>>> I thought (truncate number 1) or (floor number 1) were the standard
>>> ways, depending on what result you want if number is negative.
>> Those return the integer part, not the fraction.
>
> Hmm. You do get both parts,
>
> Welcome to GNU CLISP 2.49+ (2010-07-17) <http://clis...
> [1]> (floor 1.234 1)
> 1 ;
> 0.23399997
>
> but I'm not sure how to get just the fraction part cleanly.

You would have to read:
http://docs.oracle.com/cd/E19957-01/806-3568/ncg_gol...

But then, only 40% of programmers are computer scientists, so what do
you hopeâ?¦

--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk

Barry Margolin

1/18/2016 2:30:00 AM

0

In article <87si1vx0qo.fsf@nightsong.com>,
Paul Rubin <no.email@nospam.invalid> wrote:

> Barry Margolin <barmar@alum.mit.edu> writes:
> >> I thought (truncate number 1) or (floor number 1) were the standard
> >> ways, depending on what result you want if number is negative.
> > Those return the integer part, not the fraction.
>
> Hmm. You do get both parts,
>
> Welcome to GNU CLISP 2.49+ (2010-07-17) <http://clis...
> [1]> (floor 1.234 1)
> 1 ;
> 0.23399997
>
> but I'm not sure how to get just the fraction part cleanly.

That's what the OP was asking. One of his options was (nth-value 1
(truncate number 1)).

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

Marco Antoniotti

1/18/2016 8:50:00 AM

0

On Monday, January 18, 2016 at 1:10:22 AM UTC+1, informatimago wrote:
> Paul Rubin <no.email@nospam.invalid> writes:
>
> > Barry Margolin writes:
> >>> I thought (truncate number 1) or (floor number 1) were the standard
> >>> ways, depending on what result you want if number is negative.
> >> Those return the integer part, not the fraction.
> >
> > Hmm. You do get both parts,
> >
> > Welcome to GNU CLISP 2.49+ (2010-07-17) <http://clis...
> > [1]> (floor 1.234 1)
> > 1 ;
> > 0.23399997
> >
> > but I'm not sure how to get just the fraction part cleanly.
>
> You would have to read:
> http://docs.oracle.com/cd/E19957-01/806-3568/ncg_gol...
>
> But then, only 40% of programmers are computer scientists, so what do
> you hope...
>

Pascal, I am going to quote you on this one! :) :) :)

Cheers
--
MA

Pascal J. Bourguignon

1/18/2016 7:38:00 PM

0

Marco Antoniotti <marcoxa@gmail.com> writes:

> On Monday, January 18, 2016 at 1:10:22 AM UTC+1, informatimago wrote:
>> Paul Rubin <no.email@nospam.invalid> writes:
>>
>> > Barry Margolin writes:
>> >>> I thought (truncate number 1) or (floor number 1) were the standard
>> >>> ways, depending on what result you want if number is negative.
>> >> Those return the integer part, not the fraction.
>> >
>> > Hmm. You do get both parts,
>> >
>> > Welcome to GNU CLISP 2.49+ (2010-07-17) <http://clis...
>> > [1]> (floor 1.234 1)
>> > 1 ;
>> > 0.23399997
>> >
>> > but I'm not sure how to get just the fraction part cleanly.
>>
>> You would have to read:
>> http://docs.oracle.com/cd/E19957-01/806-3568/ncg_gol...
>>
>> But then, only 40% of programmers are computer scientists, so what do
>> you hope...
>>
>
> Pascal, I am going to quote you on this one! :) :) :)

http://techcrunch.com/2016/01/12/unlocking-trapped-...


--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk

Marco Antoniotti

1/18/2016 9:36:00 PM

0

On Monday, January 18, 2016 at 8:37:43 PM UTC+1, informatimago wrote:

> > Pascal, I am going to quote you on this one! :) :) :)
>
> http://techcrunch.com/2016/01/12/unlocking-trapped-...
>

+1. Very interesting...

MA