Price fraction: Difference between revisions
Content added Content deleted
(Price fraction en BASIC256) |
(Added tableless Forth version) |
||
Line 1,898: | Line 1,898: | ||
>r bounds begin dup @ r@ > while cell+ repeat |
>r bounds begin dup @ r@ > while cell+ repeat |
||
r> drop official@ ;</lang> |
r> drop official@ ;</lang> |
||
This one is done in the spirit of "Thinking Forth" and doesn't use any tables at all. |
|||
<lang>: ?adjust 1+ over and if 2* 15 and >r 2 - r> then ; |
|||
: accumulate >r dup >r + r> r> ; |
|||
: classify dup 0> if 1- then 5 / ; |
|||
: calculate do i ?adjust accumulate loop drop drop 100 min ; |
|||
: normalize classify >r 0 10 2 r> 1+ 0 calculate ; |
|||
: print s>d <# # # [char] . hold #s #> type ; |
|||
: test cr 101 0 ?do i print i 2 spaces normalize print cr 5 +loop ; |
|||
test</lang> |
|||
Output: |
|||
<pre> |
|||
0.00 0.10 |
|||
0.05 0.10 |
|||
0.10 0.18 |
|||
0.15 0.26 |
|||
0.20 0.32 |
|||
0.25 0.38 |
|||
0.30 0.44 |
|||
0.35 0.50 |
|||
0.40 0.54 |
|||
0.45 0.58 |
|||
0.50 0.62 |
|||
0.55 0.66 |
|||
0.60 0.70 |
|||
0.65 0.74 |
|||
0.70 0.78 |
|||
0.75 0.82 |
|||
0.80 0.86 |
|||
0.85 0.90 |
|||
0.90 0.94 |
|||
0.95 0.98 |
|||
1.00 1.00 |
|||
</pre> |
|||
=={{header|Fortran}}== |
=={{header|Fortran}}== |