Re: exercise in double number arithmetic

Liste des GroupesRevenir à cl forth 
Sujet : Re: exercise in double number arithmetic
De : melahi_ahmed (at) *nospam* yahoo.fr (Ahmed)
Groupes : comp.lang.forth
Date : 07. Jul 2024, 09:00:37
Autres entêtes
Organisation : novaBBS
Message-ID : <2c66c7a1070615fb7c6ca6daa4996cf0@www.novabbs.com>
References : 1 2 3
User-Agent : Rocksolid Light
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

Date Sujet#  Auteur
6 Jul 24 * exercise in double number arithmetic69Krishna Myneni
6 Jul 24 +* Re: exercise in double number arithmetic16Ahmed
7 Jul 24 i`* Re: exercise in double number arithmetic15Krishna Myneni
7 Jul 24 i +* Re: exercise in double number arithmetic13Ahmed
7 Jul 24 i i`* Re: exercise in double number arithmetic12Krishna Myneni
7 Jul 24 i i +* Re: exercise in double number arithmetic10Gerry Jackson
8 Jul 24 i i i`* Re: exercise in double number arithmetic9Krishna Myneni
10 Jul 24 i i i `* Re: exercise in double number arithmetic8Gerry Jackson
10 Jul 24 i i i  `* Re: exercise in double number arithmetic7dxf
10 Jul 24 i i i   +- Re: exercise in double number arithmetic1Krishna Myneni
10 Jul 24 i i i   `* Re: exercise in double number arithmetic5dxf
11 Jul 24 i i i    `* Re: exercise in double number arithmetic4Krishna Myneni
11 Jul 24 i i i     `* Re: exercise in double number arithmetic3minforth
12 Jul 24 i i i      `* Re: exercise in double number arithmetic2Krishna Myneni
12 Jul 24 i i i       `- Re: exercise in double number arithmetic1minforth
7 Jul 24 i i `- Re: exercise in double number arithmetic1Ahmed
7 Jul 24 i `- Re: exercise in double number arithmetic1minforth
6 Jul 24 +* Re: exercise in double number arithmetic3Ahmed
7 Jul 24 i`* Re: exercise in double number arithmetic2Krishna Myneni
7 Jul 24 i `- Re: exercise in double number arithmetic1Ahmed
7 Jul 24 +* Re: exercise in double number arithmetic14mhx
7 Jul 24 i`* Re: exercise in double number arithmetic13Ahmed
7 Jul 24 i +- Re: exercise in double number arithmetic1mhx
7 Jul 24 i +* Re: exercise in double number arithmetic2minforth
7 Jul 24 i i`- Re: exercise in double number arithmetic1Ahmed
7 Jul 24 i `* Re: exercise in double number arithmetic9Ahmed
7 Jul 24 i  `* Re: exercise in double number arithmetic8Ahmed
7 Jul 24 i   `* Re: exercise in double number arithmetic7mhx
7 Jul 24 i    +- Re: exercise in double number arithmetic1Ahmed
8 Jul 24 i    `* Re: exercise in double number arithmetic5Krishna Myneni
8 Jul 24 i     `* Re: exercise in double number arithmetic4Ahmed
8 Jul 24 i      +- Re: exercise in double number arithmetic1minforth
8 Jul 24 i      `* Re: exercise in double number arithmetic2Krishna Myneni
8 Jul 24 i       `- Re: exercise in double number arithmetic1Ahmed
14 Jul 24 `* Re: exercise in double number arithmetic35Marc Olschok
14 Jul 24  +- Re: exercise in double number arithmetic1Marc Olschok
15 Jul 24  +* Re: exercise in double number arithmetic12Krishna Myneni
15 Jul 24  i+* Re: exercise in double number arithmetic8minforth
15 Jul 24  ii`* Re: exercise in double number arithmetic7minforth
15 Jul 24  ii `* Re: exercise in double number arithmetic6Ahmed
15 Jul 24  ii  `* Re: exercise in double number arithmetic5minforth
15 Jul 24  ii   +- Re: exercise in double number arithmetic1minforth
15 Jul 24  ii   +- Re: exercise in double number arithmetic1Ahmed
15 Jul 24  ii   `* Re: exercise in double number arithmetic2albert
15 Jul 24  ii    `- Re: exercise in double number arithmetic1minforth
15 Jul 24  i+- Re: exercise in double number arithmetic1Anton Ertl
15 Jul 24  i+- Re: exercise in double number arithmetic1Gerry Jackson
31 Jul 24  i`- Re: exercise in double number arithmetic1Marc Olschok
15 Jul 24  `* Re: exercise in double number arithmetic21minforth
15 Jul 24   `* recursion (was: exercise in double number arithmetic)20Anton Ertl
15 Jul 24    +* Re: recursion10Marc Olschok
15 Jul 24    i`* Re: recursion9Ruvim
15 Jul 24    i +* Re: recursion5Gerry Jackson
15 Jul 24    i i+* Re: recursion2Gerry Jackson
16 Jul 24    i ii`- Re: recursion1Gerry Jackson
16 Jul 24    i i`* Re: recursion2Ruvim
16 Jul 24    i i `- Re: recursion1dxf
16 Jul 24    i +- Re: recursion1mhx
16 Jul 24    i `* Re: recursion2Ruvim
16 Jul 24    i  `- Re: recursion1Ruvim
16 Jul 24    `* Re: recursion9sjack
16 Jul 24     +- Re: recursion1sjack
16 Jul 24     +* Re: recursion4minforth
16 Jul 24     i`* Re: recursion3sjack
16 Jul 24     i `* Re: recursion2minforth
16 Jul 24     i  `- Re: recursion1mhx
17 Jul 24     `* Re: recursion3dxf
22 Jul 24      `* Re: recursion2Stephen Pelc
22 Jul 24       `- Re: recursion1Anton Ertl

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal