Deutsch   English   Français   Italiano  
<v6fdrf$ie3q$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!feeds.phibee-telecom.net!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Krishna Myneni <krishna.myneni@ccreweb.org>
Newsgroups: comp.lang.forth
Subject: Re: exercise in double number arithmetic
Date: Sun, 7 Jul 2024 20:02:37 -0500
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <v6fdrf$ie3q$1@dont-email.me>
References: <v6c8v0$3usoe$1@dont-email.me>
 <nnd$190e18f3$02eb8e44@e16a1d647fb55d93>
 <8da4b31b5cb3f13d9c296278d6821e6f@www.novabbs.com>
 <db3806e0ad371735050140c7a6b35f24@www.novabbs.com>
 <06259926ff879b77247d41e9625b3364@www.novabbs.com>
 <1c9d7fdc4b5b9bc4cb38e1993a68fb15@www.novabbs.com>
 <686af9fbeca7b6bb6d657b90a1d24d1c@www.novabbs.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 08 Jul 2024 03:02:39 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="3976a2341be6c78ccb29ccae56d7dd75";
	logging-data="604282"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX189cSIMJ74E4mZtmAvnTaP5"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:ZZid2N2i5QQ2WCMueZK4bzETtz8=
Content-Language: en-US
In-Reply-To: <686af9fbeca7b6bb6d657b90a1d24d1c@www.novabbs.com>
Bytes: 2174

On 7/7/24 15:52, mhx wrote:
> OK, let's extend it a little.
> 
> : CHS ( M N -- M!/{M-N}!/N! )
>      DUP local  N
>       -  local M-N
>      1.  N 1+ 1 DO  M-N I +  I  M*/  LOOP ;
> 

Great! My non-locals version is

\ Compute binomial coefficient as a double length number
: binom ( n k -- d )
     dup >r - 1 s>d
     r> 1+ 1 ?DO
       2 pick I + I m*/
     LOOP  rot drop ;

130 65 binom d.
95067625827960698145584333020095113100  ok

This provides a nice example for use of double length number 
computation, thanks to Albert.

As a side benefit to this exercise, I discovered that my division 
overflow check in kForth's M*/ (and in the non-standard UTM/ used by 
M*/) was not correct. This has been fixed in kForth-64.

--
Krishna