Map range: Difference between revisions

Added solution for Action!
mNo edit summary
(Added solution for Action!)
Line 64:
 
</lang>
 
=={{header|Action!}}==
{{libheader|Action! Tool Kit}}
<lang Action!>INCLUDE "D2:REAL.ACT" ;from the Action! Tool Kit
 
PROC Map(REAL POINTER a1,a2,b1,b2,s,res)
REAL tmp1,tmp2,tmp3
 
RealSub(s,a1,tmp1) ;tmp1=s-a1
RealSub(b2,b1,tmp2) ;tmp2=b2-b1
RealMult(tmp1,tmp2,tmp3) ;tmp3=(s-a1)*(b2-b1)
RealSub(a2,a1,tmp1) ;tmp1=a2-a1
RealDiv(tmp3,tmp1,tmp2) ;tmp2=(s-a1)*(b2-b1)/(a2-a1)
RealAdd(b1,tmp2,res) ;res=b1+(s-a1)*(b2-b1)/(a2-a1)
RETURN
 
PROC Main()
BYTE i
REAL a1,a2,b1,b2,s,res
 
Put(125) PutE() ;clear screen
 
ValR("0",a1) ValR("10",a2)
ValR("-1",b1) ValR("0",b2)
 
FOR i=0 TO 10
DO
IntToReal(i,s)
Map(a1,a2,b1,b2,s,res)
PrintR(s) Print(" maps to ")
PrintRE(res)
OD
RETURN</lang>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Map_range.png Screenshot from Atari 8-bit computer]
<pre>
0 maps to -1
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
</pre>
 
=={{header|Ada}}==
Anonymous user