Hi. I am not sure if this is a bug or a feature but I thought it would be a good idea ask here because Vala handles the negative sign in a way that seems to be different from C.
This statement in C works for me:
int32_t x = 0xffffcccc;
assert (x == 0xffffcccc);
but the same thing in Vala causes me some trouble:
// fiddle with bits, the details are not important but this function will return 0xffffcccc (in this example).
int32 to_fixed (double d) {
int32 val = (int32) Math.floor (d);
int32 mant = (int32) Math.floor (0x10000 * (d - val));
val = (val << 16) | mant;
return val;
}
void test () {
int32 f;
f = 0xffffcccc; // does not compile because "Assignment: Cannot convert from `int64' to `int32'"
assert (f == 0xffffcccc);
f = to_fixed (-0.2); // this will set f to 0xffffcccc (it does compile)
// this will print "0xffffcccc == 0xffffcccc ?"
stdout.printf ("0xffffcccc == 0x%x ?\n", f);
// will fail, f is not 0xffffcccc
assert (f == 0xffffcccc);
}
Is there a way around this?