I cannot find any faults in that.
The first value returned, on the first call will be (ABuffer[0] - 0.0) / dt
which is based on the assumption that the signal starts with a zero. I presume that is what you intend.
Now, rather than asking the Stack Overflow community to check your code, you can do much better yourself. You should test the code to prove it is accurate. Test it using a unit testing framework, for example DUnitX. Feed the function values for which you can predict the output. For example, feed it values from y = x2, or y = sin(x).
The other great benefit of writing tests is that they can be executed again and again. As you develop your code you run the risk of introducing faults. The code might be correct today, but who knows whether it will still be correct after the modification you make tomorrow. If you have a strong test in place, you can defend against faults introduced during maintenance.
One comment on style is that you should not ever test = false
or = true
. The if
statement operates on boolean expressions and so comparing against a boolean value is always rather pointless. I would write your test like this:
if not IsNan(FLastDiffValue) then
dy := ABuffer[0] - FLastDiffValue
else
dy := ABuffer[0]
or like this:
if IsNan(FLastDiffValue) then
dy := ABuffer[0]
else
dy := ABuffer[0] - FLastDiffValue