While trying to use Scalar in my code, I've found some oddities.
In particular, binary promotion does a bitwise reinterpretation of an
integer when promoting to a floating point type.
This was easy enough to fix, for most cases, but it caused more
questions:
* What are the intended semantics of operations like Float and Double?
For example, I tried to write a unit test for this but I am not sure
if it is correct:
int a2 = 23;
Scalar a2_scalar(a2);
ASSERT_EQ((float)a2, a2_scalar.Float());
ASSERT_EQ((double)a2, a2_scalar.Double());
The current code here also does bitwise reinterpretation.
This comment appears in Scalar.h but I did not find it much clearer:
//----------------------------------------------------------------------
// Returns a casted value of the current contained data without
// modifying the current value. FAIL_VALUE will be returned if the type
// of the value is void or invalid.
//----------------------------------------------------------------------
* What is the intended difference between the Cast and Promote methods?
These don't have comments.
* Are the 128- and 256-bit integers expected to participate in binary
promotion the same way that other ints do? If so then it seems to me
that other parts of the code are also incorrect, for example in
PromoteToMaxType:
if (lhs_type > rhs_type) { [...]
This will cause Scalar to attempt to promote floating point types to
these wide integer types; but that doesn't seem correct to me. There
may be more such problems, I did not check exhaustively.
thanks,
Tom