54 operator float()
const {
return toFloat(); }
57 return addAligned(m_, e_, o.m_, o.e_);
65 int32_t prod = ((int32_t)m_ * (int32_t)o.m_) >> 15;
66 return normalize(prod, (int32_t)e_ + o.e_ + 15);
73 return PseudoFloat((int16_t)(m_ < 0 ? -32767 : 32767), (int16_t)30);
75 int32_t numerator = (int32_t)m_ << 15;
76 int32_t quotient = numerator / o.m_;
77 return normalize(quotient, (int32_t)e_ - o.e_ - 15);
119 void fromFloat(
float f) {
126 double mag = neg ? -(double)f : (double)f;
128 while (mag >= 32768.0) {
132 while (mag < 16384.0) {
136 int16_t mag16 = (int16_t)mag;
137 m_ = neg ? (int16_t)(-(int32_t)mag16) : mag16;
141 float toFloat()
const {
142 return (
float)((double)m_ *
pow(2.0, (
double)e_));
147 static PseudoFloat normalize(int32_t val, int32_t e) {
148 if (val == 0)
return PseudoFloat((int16_t)0, (int16_t)0);
150 int64_t mag = neg ? -(int64_t)val : (int64_t)val;
151 while (mag > 32767) {
155 while (mag < 16384) {
159 int16_t mi = (int16_t)(neg ? -mag : mag);
165 static PseudoFloat addAligned(int16_t ma, int16_t ea, int16_t mb,
169 int32_t a = ma, b = mb;
173 b = (shift >= 31) ? 0 : (b >> shift);
177 a = (shift >= 31) ? 0 : (a >> shift);
180 return normalize(a + b, e);
uint8_t pow(uint8_t x, intmax_t power)
Definition gf.hpp:111