added floats.interpolate(), math.interpolate(), and LERP example

This commit is contained in:
Irmen de Jong
2024-11-24 08:51:34 +01:00
parent 90f1e7fd6a
commit 857d2eefca
8 changed files with 267 additions and 4 deletions

View File

@@ -662,4 +662,12 @@ log2_tab
cx16.r0++
return v0 + cx16.r0
}
sub interpolate(ubyte v, ubyte inputMin, ubyte inputMax, ubyte outputMin, ubyte outputMax) -> ubyte {
; Interpolate a value v in interval [inputMin, inputMax] to output interval [outputMin, outputMax]
; There is no version for words because of lack of precision in the fixed point calculation there.
cx16.r0 = ((v-inputMin)*256+inputMax) / (inputMax-inputMin)
cx16.r0 *= (outputMax-outputMin)
return cx16.r0H + outputMin
}
}