Sujet : Re: exercise in double number arithmetic
De : krishna.myneni (at) *nospam* ccreweb.org (Krishna Myneni)
Groupes : comp.lang.forthDate : 08. Jul 2024, 02:02:37
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v6fdrf$ie3q$1@dont-email.me>
References : 1 2 3 4 5 6 7
User-Agent : Mozilla Thunderbird
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