增加iFloat64::from_raw函数接口

This commit is contained in:
2025-07-29 22:18:13 +08:00
parent 8b66098f3d
commit a2ff667b68
+17 -28
View File
@@ -62,6 +62,11 @@ public:
return static_cast<int32_t>(s1516 >> kShift);
}
static ifloat32 from_raw(int32_t raw) {
ifloat32 ret;
ret.s1516 = raw;
return ret;
}
public:
inline ifloat32& operator = (const ifloat32& other) {
s1516 = other.s1516;
@@ -99,56 +104,34 @@ public:
//Adds the two FP numbers together.
inline friend ifloat32 operator + (const ifloat32& l, const ifloat32& r) {
int64_t t = static_cast<int64_t>(l.s1516) + static_cast<int64_t>(r.s1516);
ifloat32 ret;
ret.s1516 = static_cast<int32_t>(t);
return ret;
return from_raw(t);
}
//Subtracts the two FP numbers from each other.
inline friend ifloat32 operator - (const ifloat32& l, const ifloat32& r) {
int64_t t = static_cast<int64_t>(l.s1516) - static_cast<int64_t>(r.s1516);
ifloat32 ret;
ret.s1516 = t;
return ret;
return from_raw(t);
}
inline friend ifloat32 operator * (const ifloat32& a, const float32_t& b) {
int64_t t = static_cast<int64_t>(a.s1516) * static_cast<int64_t>(b * kFloatScale);
t = t >> kShift;
ifloat32 ret;
ret.s1516 = t;
return ret;
return from_raw(t >> kShift);
}
inline friend ifloat32 operator * (const ifloat32& a, const int32_t& b) {
ifloat32 ret;
ret.s1516 = a.s1516 * b;
return ret;
return from_raw(a.s1516 * b);
}
//Multiplies two FP values together.
inline friend ifloat32 operator * (const ifloat32& a, const ifloat32& b) {
int64_t t = static_cast<int64_t>(a.s1516) * static_cast<int64_t>(b.s1516);
t = t >> kShift;
ifloat32 ret;
ret.s1516 = static_cast<int32_t>(t);
return ret;
return from_raw(static_cast<int32_t>(t >> kShift));
}
inline friend ifloat32 operator / (const ifloat32& a, const ifloat32& b) {
// pre-multiply by the base
int64_t t = static_cast<int64_t>(a.s1516) << kShift;
t /= b.s1516;
ifloat32 ret;
ret.s1516 = static_cast<int32_t>(t);
return ret;
return from_raw(static_cast<int32_t>(t/ b.s1516));
}
public:
@@ -440,6 +423,12 @@ struct iFloat3
z = z * multiplier;
}
inline void mul(const int32_t& multiplier) {
x = x * multiplier;
y = y * multiplier;
z = z * multiplier;
}
inline iFloat operator [] (const size_t i) const {
return *(&x + i);
}