Price fraction: Difference between revisions
Content added Content deleted
(Added tableless Forth version) |
(Added uBasic/4tH version) |
||
Line 4,608: | Line 4,608: | ||
</pre> |
</pre> |
||
=={{header|uBasic/4tH}}== |
|||
{{trans|Forth}} |
|||
{{works with|R3}} |
|||
<lang>For i = 0 To 100 Step 5 |
|||
Print Using "+?.##"; i, Using "+?.##"; FUNC(_Normalize (FUNC(_Classify (i)))) |
|||
Next |
|||
End |
|||
_Normalize ' normalize the price |
|||
Param (1) ' class |
|||
Local (4) ' accumulator, increment, switch and iterator |
|||
b@ = 0 : c@ = 10 : d@ = 2 ' setup accumulator, increment and switch |
|||
For e@ = 0 to a@ ' from zero to class |
|||
If And(e@ + 1, d@) Then d@ = And(d@ + d@, 15) : c@ = c@ - 2 |
|||
b@ = b@ + c@ ' switch increment if needed |
|||
Next ' accumulate price |
|||
Return (Min(b@, 100)) ' clip top of price in accumulator |
|||
' calculate class |
|||
_Classify Param (1) : Return ((a@ - (a@>0)) / 5)</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 |
|||
0 OK, 0:115</pre> |
|||
=={{header|Ursala}}== |
=={{header|Ursala}}== |
||
<lang Ursala>#import flo |
<lang Ursala>#import flo |