我创建了一个结构来表示一个定点正数。我希望小数点两边的数字包含 2 个字节。
typedef struct Fixed_t {
unsigned short floor; //left side of the decimal point
unsigned short fraction; //right side of the decimal point
} Fixed;
现在我想添加两个定点数,Fixed x
和Fixed y
。为此,我将它们视为整数并相加。
(Fixed) ( (int)x + (int)y );
但正如我的 Visual Studio 2010 编译器所说,我无法在 和 之间进行Fixed
转换int
。
这样做的正确方法是什么?
编辑:我不致力于{short floor, short fraction}
实施固定。