Deutsch   English   Français   Italiano  
<b2082c0108b670faa0a3fbfc46ec82b5@www.novabbs.com>

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

Path: ...!weretis.net!feeder9.news.weretis.net!i2pn.org!i2pn2.org!.POSTED!not-for-mail
From: minforth@gmx.net (minforth)
Newsgroups: comp.lang.forth
Subject: Re: exercise in double number arithmetic
Date: Mon, 15 Jul 2024 07:38:50 +0000
Organization: novaBBS
Message-ID: <b2082c0108b670faa0a3fbfc46ec82b5@www.novabbs.com>
References: <v6c8v0$3usoe$1@dont-email.me> <v71gpb$jsug$1@solani.org> <v71t6u$clc8$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
	logging-data="3341262"; mail-complaints-to="usenet@i2pn2.org";
	posting-account="0+ejqm+s29REto3A2x2P4fP+XaUXf51pZgtYBR0nEqI";
User-Agent: Rocksolid Light
X-Spam-Checker-Version: SpamAssassin 4.0.0
X-Rslight-Posting-User: d2a19558f194e2f1f8393b8d9be9ef51734a4da3
X-Rslight-Site: $2y$10$Jgq/8IPmdISaej1Y8tVyper7kD/To0VPG3TNMHO/ohSfVIslp.clW
Bytes: 1464
Lines: 19

Yet another fast variant without looping/recursion:

\ LOGBINOM

100 FLOATS BUFFER: LCS{ \ log sum array
: }  ( a i -- f: n ) floats + f@ ;
: }! ( a i f: n -- ) floats + f! ;
: PREP-LCS ( -- ) \ prepare array
  0e lcs{ 0 }! 100 1 DO
    lcs{ i 1- } i s>f flog f+ lcs{ i }!
  LOOP ;

: LBINOM ( n k -- binom ) \ calc binom coeff by array lookup
  2dup = over 0= or
  IF 0e
  ELSE 2dup lcs{ swap } lcs{ swap } - lcs{ swap } f- fswap f-
  THEN falog fround f>d ;

PREP-LCS
42 21 LBINOM D.