Closed wluker closed 5 years ago
Thats special, the first test is actually phase 0, and it looks like the actual processing block got the correct answer 10-20j
and 10+4294967276j
is the complex double logic approximating it, which is totally off.
const auto input = std::complex<double>(pIn[i].real(), pIn[i].imag());
const auto expected = std::complex<Type>(input * std::polar(1.0, phase));
Given that the double version of the block actually worked, I would have to guess that somehow const auto input = std::complex<double>(pIn[i].real(), pIn[i].imag());
failed. But thats crazy, its just converting the numbers 10 and 20 as long longs to doubles.
Anyway, not really sure what went wrong, can you print some intermediate values from the lines above and see where things went wrong?
I think the issue is size_t i
in:
for (size_t i = 0; i < buffIn.elements(); i++)
{
pIn[i] = std::complex<Type>(Type(10*i), Type(-20*i));
}
This program:
#include <iostream>
int main() {
size_t i = 1;
int64_t q = int64_t(-20*i);
std::cout << q << std::endl;
return 0;
}
prints : 4294967276
and when I use int i=1
I get the expected -20.
Somehow mixing unsigned and signed types doesn't work as expected for int64_t on a 32-bit platform?
This post Talks about what happens when multiplying signed and unsigned integers. Short answer is, as long as they are the same rank (size), a signed is implicitly typecast to unsigned.
So it looks like -20 (an int) times 1 (an unsigned long) probably becomes an unsigned 32-bit type. In this case the contents of the resulting type is not -20, but 4294967276 which is the unsigned equivalent. So typecasting this unsigned 32-bit type to a signed 64-bit type basically stores the value as-is which fits into the 64-bit type and does not sign extend it, because its unsigned.
On a 64-bit platform, the size_t is already 64-bits, so its just fine.
So good find, I will just be more explicit with the type.
Pushed a fix, this is in PothosComms project: https://github.com/pothosware/PothosComms/commit/17d9cda18083e098890846427b4643ea1a015c65
After installing PothosComms I ran
PothosUtil --self-tests
and got the following error.Specifically the failing test in TestRotate.cpp is
testRotateTmpl<int64_t>(phase);
. If I comment out theint64_t
test the other integer tests pass, so this is probably something to do with a 32-bit system.