Created
January 11, 2026 17:16
-
-
Save robertoostenveld/54be45fb4d1a36954874228a2fd3d921 to your computer and use it in GitHub Desktop.
Lookup table in Berry programming language
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def lookup(x) | |
| x = 1.0 * x # convert to float | |
| var xl = [0., 1., 2., 3., 9., 10.] | |
| var yl = [0., 1., 2., 3., 9., 10.] # this would typically contain other values | |
| var n = size(xl) | |
| if x <= xl[0] | |
| return yl[0] | |
| elif x >= xl[n - 1] | |
| return yl[n - 1] | |
| else | |
| for i : 0..(n - 2) | |
| var x1 = xl[i] | |
| var x2 = xl[i + 1] | |
| if x >= x1 && x <= x2 | |
| var y1 = yl[i] | |
| var y2 = yl[i + 1] | |
| return ((x - x1) / (x2 - x1)) * (y2 - y1) + y1 | |
| end | |
| end # for | |
| end # else | |
| end # def |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment