Map range: Difference between revisions
Content added Content deleted
(→{{header|C++}}: (Whoops)!) |
(Added PureBasic) |
||
Line 54: | Line 54: | ||
map_value(10) = 0 |
map_value(10) = 0 |
||
</pre> |
</pre> |
||
=={{header|PureBasic}}== |
|||
<lang PureBasic>Structure RR |
|||
a.f |
|||
b.f |
|||
EndStructure |
|||
Procedure.f MapRange(*a.RR, *b.RR, s) |
|||
Protected.f a1, a2, b1, b2 |
|||
a1=*a\a: a2=*a\b |
|||
b1=*b\a: b2=*b\b |
|||
ProcedureReturn b1 + ((s - a1) * (b2 - b1) / (a2 - a1)) |
|||
EndProcedure |
|||
;- Test the function |
|||
If OpenConsole() |
|||
Define.RR Range1, Range2 |
|||
Range1\a=0: Range1\b=10 |
|||
Range2\a=-1:Range2\b=0 |
|||
; |
|||
For i=0 To 10 |
|||
PrintN(RSet(Str(i),2)+" maps to "+StrF(MapRange(@Range1, @Range2, i),1)) |
|||
Next |
|||
EndIf</lang> |
|||
<pre> 0 maps to -1.0 |
|||
1 maps to -0.9 |
|||
2 maps to -0.8 |
|||
3 maps to -0.7 |
|||
4 maps to -0.6 |
|||
5 maps to -0.5 |
|||
6 maps to -0.4 |
|||
7 maps to -0.3 |
|||
8 maps to -0.2 |
|||
9 maps to -0.1 |
|||
10 maps to 0.0</pre> |
|||
=={{header|Python}}== |
=={{header|Python}}== |