Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -0,0 +1,5 @@
mapRange = (a1,a2,b1,b2,s) ->
t = b1 + ((s-a1)*(b2 - b1)/(a2-a1))
for s in [0..10]
console.log("#{s} maps to #{mapRange(0,10,-1,0,s)}")

View file

@ -0,0 +1,9 @@
defmodule RC do
def map_range(a1 .. a2, b1 .. b2, s) do
b1 + (s - a1) * (b2 - b1) / (a2 - a1)
end
end
Enum.each(0..10, fn s ->
:io.format "~2w map to ~7.3f~n", [s, RC.map_range(0..10, -1..0, s)]
end)

View file

@ -1,8 +1,7 @@
use v6;
# Author: P. Seebauer
sub the_function(Range $a, Range $b, $s ) {
my ($a1, $a2, $b1, $b2) = ($a, $b)».bounds;
sub the_function(Range $a, Range $b, $s) {
my ($a1, $a2) = $a.bounds;
my ($b1, $b2) = $b.bounds;
return $b1 + (($s-$a1) * ($b2-$b1) / ($a2-$a1));
}
for ^11 -> $x {say "$x maps to {the_function(0..10,-1..0, $x)}"}
for ^11 -> $x { say "$x maps to {the_function(0..10, -1..0, $x)}" }

View file

@ -1,5 +1,6 @@
sub getmapper(Range $a, Range $b) {
my ($a1, $a2, $b1, $b2) = ($a, $b)».bounds;
my ($a1, $a2) = $a.bounds;
my ($b1, $b2) = $b.bounds;
return -> $s { $b1 + (($s-$a1) * ($b2-$b1) / ($a2-$a1)) }
}

View file

@ -1,12 +1,11 @@
/*REXX program maps a number from one range to another range. */
rangeA = '0 10'
rangeB = '-1 0'
do j=0 to 10
say right(j,3) ' maps to ' mapRange(rangeA, rangeB, j)
/*REXX program maps a range of numbers from one range to another range. */
rangeA = 0 10 /*or: rangeA = ' 0 10 ' */
rangeB = -1 0 /*or: rangeB = " -1 0 " */
parse var RangeA L H
inc=1
do j=L to H by inc*(1-2*sign(H<L)) /*BY: +inc │ -inc) */
say right(j,digits()) ' maps to ' mapRange(rangeA,rangeB,j)
end /*j*/
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────MAPRANGE subroutine─────────────────*/
mapRange: procedure; arg a1 a2,b1 b2,x; return b1+(x-a1)*(b2-b1)/(a2-a1)
mapRange: procedure; arg a1 a2,b1 b2,s; return b1+ (s-a1)*(b2-b1)/(a2-a1)

View file

@ -1,9 +1,11 @@
/*REXX program maps a number from one range to another range. */
do j=0 to 10
say right(j,3) ' maps to ' mapRange(0 10, -1 0, j)
/*REXX pgm maps a range of numbers from one range to another with inc=½.*/
rangeA = 10 0 /*or: rangeA = ' 10 0 ' */
rangeB = -1 0 /*or: rangeB = " -1 0 " */
parse var RangeA L H /*note the LOW & HIGH values in A*/
inc= 1/2 /*use a different step size (inc)*/
do j=L to H by inc*(1-2*sign(H<L)) /*BY: +inc │ -inc) */
say right(j,9) ' maps to ' mapRange(rangeA,rangeB,j)
end /*j*/
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────MAPRANGE subroutine─────────────────*/
mapRange: procedure; arg a1 a2,b1 b2,x; return b1+(x-a1)*(b2-b1)/(a2-a1)
mapRange: procedure; arg a1 a2,b1 b2,s; return b1+ (s-a1)*(b2-b1)/(a2-a1)

View file

@ -1,9 +1,12 @@
/*REXX program maps a number from one range to another range. */
rangeA = '0 10'; parse var rangeA a1 a2
rangeB = '-1 0'; parse var rangeB b1 b2
do j=0 to 10
say right(j,3) ' maps to ' b1+(x-a1)*(b2-b1)/(a2-a1)
end /*j*/
/*stick a fork in it, we're done.*/
/*REXX program maps a range of numbers from one range to another range. */
rangeA = 0 10
rangeB = -1 0
inc=1
call mapRange rangeA, RangeB, inc
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────MAPRANGE subroutine─────────────────*/
mapRange: procedure; parse a1 a2, b1 b2, inc
do s=a1 to a2 by inc*(1-2*sign(a2<a1)) /*BY: +inc │ -inc */
say right(s,digits()) ' maps to ' b1+(s-a1)*(b2-b1)/(a2-a1)
end /*s*/ /*↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑*/
return /*════════════t════════════*/