From: eugene kim
Subject: how do i get quotient?
Date: 
Message-ID: <ab323h$5jp$1@newsreader.mailgate.org>
7 /3 = 2 ..remainder 1
how do i get 2 here?

thank you

From: Hannah Schroeter
Subject: Re: how do i get quotient?
Date: 
Message-ID: <ab337r$k3b$7@c3po.schlund.de>
Hello!

In article <············@newsreader.mailgate.org>,
eugene kim  <··········@hotmail.com> wrote:
>7 /3 = 2 ..remainder 1
>how do i get 2 here?

(multiple-value-bind
  (quotient remainder) (floor 7 3)
  #| do something with those |#)

Kind regards,

Hannah.
From: jb
Subject: Re: how do i get quotient?
Date: 
Message-ID: <3cd57136_1@news2.newsgroups.com>
Hannah Schroeter wrote:

>>7 /3 = 2 ..remainder 1
>>how do i get 2 here?
> 
> (multiple-value-bind
>   (quotient remainder) (floor 7 3)
>   #| do something with those |#)

Well, in C is this more easily done...
-- 
Janos Blazi

Il n'y a gu�re dans la vie qu'une pr�occupation grave: c'est la mort; 
(Dumas) 



-----------== Posted via Newsfeeds.Com - Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The #1 Newsgroup Service in the World!
-----= Over 100,000 Newsgroups - Ulimited Fast Downloads - 19 Servers =-----
From: Kaz Kylheku
Subject: Re: how do i get quotient?
Date: 
Message-ID: <uNgB8.11348$a04.51175@tor-nn1.netcom.ca>
On Sun, 05 May 2002 20:10:30 +0200, jb <········@yahoo.de> wrote:
>Hannah Schroeter wrote:
>
>>>7 /3 = 2 ..remainder 1
>>>how do i get 2 here?
>> 
>> (multiple-value-bind
>>   (quotient remainder) (floor 7 3)
>>   #| do something with those |#)
>
>Well, in C is this more easily done...

That statement requires qualification. The C infix syntax appears to be more
terse in the number of characters.

  q = x / y;
  r = x % y;

versus

  (multiple-value-setq (q r) (floor x y))

However, in the number of *symbols*, they are even: twelve and twelve;
so the greater verbiage of the Lisp version is attributable to the
long spelling of multiple-value-setq and floor, which can be replaced
by macros having terse names. The presence of parentheses is offset by
not having to repeat x and y, and invoke two operators independently.
Incidentally, a C compiler has to be extra clever to recognize this case
and reduce it to a single machine instruction that pulls out the quotient
and remainder.

Now there deeper issues. C doesn't have arbitrary precision integers,
so you run into limitations that could show up as a software defect. The
behavior of a C program upon division by zero is undefined, meaning that
the program could halt or continue with a garbage result. Until C99, the
truncation behavior of the % operator was implementation-defined if the
quotient is negative, meaning that it could behave like the Lisp truncate,
floor or even round functions. In Lisp, you can choose the exact behavior
you want by using the appropriate function.

For portability, the C should really be:

  #include <stdlib.h>

  /*...*/

    ldiv_t result = ldiv(x, y);

    q = result.quot;
    r = result.rem;

Of course, ldiv performs truncation toward zero, so this resembles

  (multiple-value-setq (q r) (truncate x y))

rather than (... (floor x y)). Note how clumsy it is to emulate multiple
value returning with a struct in C; the syntax is no longer all that nice.

And of course, to write the *real* equivalent in C, we would have to pull out
some third-party library for large integer manipulation, such as GNU MP,
FreeLIP or whatever. To avoid very messy syntax with lots of
programmer-generated bookkeeping, you'd have to switch to C++ and wrap these
things with classes. Then, of course, you'd run into problems with C++'s
weak ``method combination'' system, in trying to make these new numbers
interoperate with built-in arithmetic types...

-- 
A garbage collector in a Java environment must necessarily be conservative,
lest it wipe away the language entirely.
From: jb
Subject: Re: how do i get quotient?
Date: 
Message-ID: <3cd5a135_2@news2.newsgroups.com>
Sorry, but in C I simply write

7/3

and the result is 2,recall this correctly. This is what the poster of the 
original message wanted. recall this correctly. So you have only three 
"symbols" here.

The (scholarly) answer

(multiple-value-bind
  (quotient remainder) (floor 7 3)
  #| do something with those |#)

is in my opinion an overkill for this simple problem and the answer
(floor 7 3) would have sufficed. This answer would have consisted of three 
symbols as well. And the "floor" function is nexessary because CL has 
rational numbers and C has none.

-- 
Janos Blazi

Il n'y a gu�re dans la vie qu'une pr�occupation grave: c'est la mort; 
(Dumas) 



-----------== Posted via Newsfeeds.Com - Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The #1 Newsgroup Service in the World!
-----= Over 100,000 Newsgroups - Ulimited Fast Downloads - 19 Servers =-----
From: Kaz Kylheku
Subject: Re: how do i get quotient?
Date: 
Message-ID: <DXhB8.11362$a04.51248@tor-nn1.netcom.ca>
On Sun, 05 May 2002 23:35:17 +0200, jb <········@yahoo.de> wrote:
>Sorry, but in C I simply write
>
>7/3
>
>and the result is 2,recall this correctly. This is what the poster of the 
>original message wanted. recall this correctly. So you have only three 
>"symbols" here.
>
>The (scholarly) answer
>
>(multiple-value-bind
>  (quotient remainder) (floor 7 3)
>  #| do something with those |#)
>
>is in my opinion an overkill for this simple problem and the answer
>(floor 7 3) would have sufficed.

Your argument related to the special case of 7 and 3 leads to the conclusion
that in both languages, you can instead just write the symbol 2 in place
of (floor 7 3) or 7/3.

But one has to suspect that the question is more general, and that 7/3 is just
an example; in the general case, the divisor and dividend are likely going to
be unknowns.

>This answer would have consisted of three 
>symbols as well. And the "floor" function is nexessary because CL has 
>rational numbers and C has none.

That sounds as if floor is a workaround for the problem of rational numbers.
But in reality, it's simply a division function that provides well-defined
residue semantics. Such a function is useful regardless of the support for
rational numbers.

-- 
A garbage collector in a Java environment must necessarily be conservative,
lest it wipe away the language entirely.
From: jb
Subject: Re: how do i get quotient?
Date: 
Message-ID: <3cd5ae98_2@news2.newsgroups.com>
Kaz Kylheku wrote:
> Your argument related to the special case of 7 and 3 leads to the
> conclusion that in both languages, you can instead just write the symbol 2
> in place of (floor 7 3) or 7/3.
> 
> But one has to suspect that the question is more general, and that 7/3 is
> just an example; in the general case, the divisor and dividend are likely
> going to be unknowns.

And you cannot write "(floor x y)"? (Here I admit that I never understood, 
for what "ffloor" was needed.) 

> That sounds as if floor is a workaround for the problem of rational
> numbers. 

I still think it is in a way.

> But in reality, it's simply a division function that provides
> well-defined residue semantics.

But if Lisp had no rational numbers then you could simply write

(/ 7 3) and / could be as well defined as floor is (it depends only on the 
language, how well defined an operator is). Or maybe I did not understand 
all this.

But I did not want to argue against "floor", which is a nice thing. I simply 
thought that if somebody does not know how to divide 3 omto 7, which is a 
rather elementary concept, then he is a beginner and is probably frightened 
by a complicated answer, even if it is the right and most precise one from 
a scholarly point of view.

-- 
Janos Blazi

Il n'y a gu�re dans la vie qu'une pr�occupation grave: c'est la mort; 
(Dumas) 



-----------== Posted via Newsfeeds.Com - Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The #1 Newsgroup Service in the World!
-----= Over 100,000 Newsgroups - Ulimited Fast Downloads - 19 Servers =-----
From: jb
Subject: Re: how do i get quotient?
Date: 
Message-ID: <3cd5a176_2@news2.newsgroups.com>
jb wrote:

> Sorry, but in C I simply write
> 
> 7/3
> 
> and the result is 2,if I recall this correctly. This is what the poster of 
the
> original message wanted. recall this correctly. So you have only three
> "symbols" here.
> 
> The (scholarly) answer
> 
> (multiple-value-bind
>   (quotient remainder) (floor 7 3)
>   #| do something with those |#)
> 
> is in my opinion an overkill for this simple problem and the answer
> (floor 7 3) would have sufficed. This answer would have consisted of three
> symbols as well. And the "floor" function is nexessary because CL has
> rational numbers and C has none.
> 

-- 
J B

Il n'y a gu�re dans la vie qu'une pr�occupation grave: c'est la mort; 
(Dumas) 



-----------== Posted via Newsfeeds.Com - Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The #1 Newsgroup Service in the World!
-----= Over 100,000 Newsgroups - Ulimited Fast Downloads - 19 Servers =-----
From: Hannah Schroeter
Subject: Re: how do i get quotient?
Date: 
Message-ID: <ab5nll$hlt$1@c3po.schlund.de>
Hello!

In article <··········@news2.newsgroups.com>, jb  <········@yahoo.de> wrote:
>Hannah Schroeter wrote:

>>>7 /3 = 2 ..remainder 1
>>>how do i get 2 here?

>> (multiple-value-bind
>>   (quotient remainder) (floor 7 3)
>>   #| do something with those |#)

>Well, in C is this more easily done...

If you need both values, in C you do 2 calculations, except if the
compiler is very smart.

Additionally, you can choose between the different modes of
quotient/remainder calculation. Lookup #'floor, #'ceiling,
#'truncate, #'round and their respective variants prefixed with
#\f, i.e. #'ffloor etc.

Another way to get your number 2 in your example would be
(floor (/ 7 3)). (the #'/ operator yields the exact value, in
this case as rational number. floor truncates it towards
negative infinity)

Kind regards,

Hannah.
From: Thomas Bushnell, BSG
Subject: Re: how do i get quotient?
Date: 
Message-ID: <8766215gvr.fsf@becket.becket.net>
······@schlund.de (Hannah Schroeter) writes:

> If you need both values, in C you do 2 calculations, except if the
> compiler is very smart.

Well, GCC does it without a hitch on the 386.  "Very smart" isn't
really that uncommon these days.  I compiled the following function:

  foo(int a, int b)
  {
    bar (a / b, a % b);
  }

and got the following result:

foo:
	pushl %ebp
	movl %esp,%ebp
	subl $8,%esp
	movl 8(%ebp),%eax
	addl $-8,%esp
	cltd
	idivl 12(%ebp)
	pushl %edx
	pushl %eax
	call bar
	leave

Thomas
From: Felix Schlesinger
Subject: Re: how do i get quotient?
Date: 
Message-ID: <slrnada7qq.ev.fam_Schlesinger@schlesinger.dyndns.org>
eugene kim schrieb
> 7 /3 = 2 ..remainder 1
> how do i get 2 here?

(floor 7 3)

Ciao
  Felix
From: Eduardo Muñoz
Subject: Re: how do i get quotient?
Date: 
Message-ID: <u3cx6n57w.fsf@jet.es>
eugene kim <··········@hotmail.com> writes:

> 7 /3 = 2 ..remainder 1
> how do i get 2 here?

The HyperSpec is your friend. You should download
a copy if you are learning CL.

http://www.xanalys.com/software_tools/reference/HyperSpec/Body/f_sl.htm

This is the entry for '/'. At the end of the page
you will get pointers to floor, ceiling, truncate &
round. One of them will do what you want.

-- 

Eduardo Mu�oz