Skip to content

Instantly share code, notes, and snippets.

@robertoostenveld
Created January 11, 2026 17:16
Show Gist options
  • Select an option

  • Save robertoostenveld/54be45fb4d1a36954874228a2fd3d921 to your computer and use it in GitHub Desktop.

Select an option

Save robertoostenveld/54be45fb4d1a36954874228a2fd3d921 to your computer and use it in GitHub Desktop.
Lookup table in Berry programming language
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