Path: ...!weretis.net!feeder9.news.weretis.net!i2pn.org!i2pn2.org!.POSTED!not-for-mail From: melahi_ahmed@yahoo.fr (Ahmed) Newsgroups: comp.lang.forth Subject: Re: exercise in double number arithmetic Date: Sun, 7 Jul 2024 08:00:37 +0000 Organization: novaBBS Message-ID: <2c66c7a1070615fb7c6ca6daa4996cf0@www.novabbs.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: i2pn2.org; logging-data="2439017"; mail-complaints-to="usenet@i2pn2.org"; posting-account="hogn68ACS2mVV0PcPkBzD/3kIXL71Lu5zlxJ/QczJJE"; User-Agent: Rocksolid Light X-Spam-Checker-Version: SpamAssassin 4.0.0 X-Rslight-Site: $2y$10$x4vGajaaYeBZZVOT8K9TluE0At9bNW7AyG.BMAcoKNGIqBrg5jdt2 X-Rslight-Posting-User: cdd77cd46f5cefdf617b921703a970831cf47f35 Bytes: 2247 Lines: 43 I noticed there was a problem in my double artihmetic version of the program. It is about table's elements addressing. for example, it gives 2 for 26 0 istead of 1, and the error spreads for the next calculations Here is the new version. It works fine for n<=49 (it is due to my choice of 50 lines of Pascal's triangle) create table 50 50 2* * cells allot table 50 50 * 2* cells erase : table.init 50 0 do 1. table i 50 * 2* cells + 2! loop ; table.init : table.calc 50 1 do 50 1 do table j 1 - 50 * i 1 - + 2* cells + 2@ table j 1 - 50 * i + 2* cells + 2@ d+ table j 50 * i + 2* cells + 2! loop loop ; table.calc : bcoef_tab swap 50 * swap + 2* cells table + 2@ d. ; Here a comaprison with results given table version and minforth verson side by side, the results are identical. : BCOEF ( n k -- ) swap s>f 1e 1+ 1 ?DO fover 1e f+ i s>f f- i s>f f/ f* LOOP fswap fdrop fround f>d d. ; minforth version works for any n and k. It uses the fact that: C(n,k) = prod((n+1-i)/(i)) for i = 1 to k = ((n+1-k)/(k))...(n/1) = (n!/(n-k)!)/k! : go 50 0 do i 1+ 0 ?do cr j . i . j i bcoef_tab j i bcoef loop loop ; Ahmed