Accumulator factory: Difference between revisions
→{{header|Forth}}: added float version and explanation for why idiomatic Forth does not satisfy requirement 2
(→{{header|Kotlin}}: Added code and output previously omitted) |
(→{{header|Forth}}: added float version and explanation for why idiomatic Forth does not satisfy requirement 2) |
||
Line 952:
2 foo . \ 3
3 foo . \ 6</lang>
The idiomatic way to deal with floats is to have a float version of this code; for a mixture of integers and floats, you decide at the start to use a float accumulator, and convert integers to floats explicitly:
<lang forth>
: faccumulator ( r "name" -- )
create falign f,
does> ( r1 -- r2 )
faligned dup f@ f+ fdup f! ;
1 s>f faccumulator x
5 s>f x fdrop
3 s>f faccumulator y \ unused
2.3e x f.
</lang>
=={{header|F Sharp|F#}}==
|