Bézier Curves Help

I’m trying to make a perfect curve, but it’s acting up a little.

local function Lerp(p0,p1,a)
	return (1 - a) * p0 + a * p1
end

local function Quadratic(p0,p1,p2,a)
	local L1 = Lerp(p0,p1,a)
	local L2 = Lerp(p1,p2,a)
	return Lerp(L1,L2,a)
end

for i = 0, 1, 0.1 do
	print(Quadratic(0, 100, 0, i))
end

Instead of outputting 0 when it is 1, it outputs 2.220446 something.
Is there a reason for this? Am I doing it wrong?

image

I believe this is just floating point inaccuracies because of the 0.1.

for i = 0, 1, 0.1 do
	print(string.format("%s == 1 = %s", i, tostring(i == 1)))
	print(Quadratic(0, 100, 0, i))
end

image

If you do for i = 0, 10, 1 and then divide i by 10 inside the for loop then it works as expected

for i = 0, 10, 1 do
	i = i / 10
	print(string.format("%s == 1 = %s", i, tostring(i == 1)))
	print(Quadratic(0, 100, 0, i))
end

image

Also 2.22e-14 means 2.22 * 10^-14 (basically a really small number that is almost 0)

1 Like

Wow really? Never heard of that before.
Thank you for the help.