Closed daniel-mohr closed 2 years ago
The bit shift is not the same as modulo. It just corrects a small overflow. So using it together with delay the modulo does not work.
You mentioned this typo already in fletcher16
.
The bit shift is not the same as modulo. It just corrects a small overflow. So using it together with delay the modulo does not work. You mentioned this typo already in
fletcher16
.
Yes, It only works for small overflows, and the sum of (s1 & xxxx) + (s1 >> bits) should not be beyond the modulo number. So it should work in the add() in the classes, as it is done after every addition.
Would it be possible to add your test code to find the bug to the unit test ? In the test folder?
@daniel-mohr Do you expect the 64 bit version to work? It will take a lot of time (I mean a LOT) to test this as the loop takes long to "overflow".
The optimization for the 64 bit function is hard to test and probably called not that much. The gain is minimal given that the loop itself takes far more time.
So can you roll back the 64 bit version too?
Yes, good idea to put it in as unit test. I never did this. But I will try this later.
Oh, sorry, I skipped fletcher64
. But I expect it's the same. Let us see if I can somehow manage to check this as a unittest.
unit tests are pretty straightforward in this, just compare a value with the function return.
To make the output 'debug able' do not put more than ~20 or so tests in a single unit test (or print some divider whatever).
Note I updated your sketch above to get syntax highlighting.
Add cpp after the three backquotes
Sorry, but there is a bug. It comes in with 33afeaa5984d800a14aec638c3645b9450183f87. I do not see quickly the problem. I will try to look at it later.
Using the following sketch I get not the same result calculating using
fletcher32
orFletcher32
. I also implemented a very basic own one which gives the same result asFletcher32
.The output on an Arduino Nano (ATmega 328P):
The output on an Arduino MKRZERO (SAMD21):
And here the used sketch: