Sujet : Re: exercise in double number arithmetic
De : krishna.myneni (at) *nospam* ccreweb.org (Krishna Myneni)
Groupes : comp.lang.forthDate : 07. Jul 2024, 00:50:28
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v6cl84$obt$2@dont-email.me>
References : 1 2
User-Agent : Mozilla Thunderbird
On 7/6/24 16:59, Ahmed wrote:
Why using double arithmetic when we can use simply Pascal triangle?
...
Yes! I had forgotten about Pascal's triangle when I coded my solution. A benefit of your double number solution is that it works on both 32-bit and 64-bit Forth systems.
Here's my solution for the specific problem, which will only work on a 64-bit system:
: solution ( -- d)
1 s>d 43 22 do i 1 m*/ loop d>f
21 dup s>d rot 2 do I 1 m*/ loop d>f
f/ fround f>d ;
We don't have D/ in the standard, which necessitated the conversion to float for dividing two double length numbers and then convert back to double.
-- Krishna