Skip to content

Commit

Permalink
style: 仮数部のけち表現まわりの処理をわかりやすいように修正
Browse files Browse the repository at this point in the history
  • Loading branch information
yutotnh committed Aug 7, 2023
1 parent a5e80ef commit d04db95
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/spirit/src/bfloat16.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ float bfloat16_to_float32(const uint16_t bfloat16)
return std::numeric_limits<float>::quiet_NaN() * sign;
}
} else {
constexpr uint32_t exponent_bias = 127 + 7; // 128: 指数部の0x7Fのオフセット, 7: 仮数部のビット数
return std::ldexp(static_cast<float>(mantissa) + 128.0F, exponent - exponent_bias) * sign;
constexpr uint32_t exponent_bias = 127 + 7; // 127: 指数部の0x7Fのオフセット, 7: 仮数部のビット数
const uint32_t actual_mantissa = mantissa + 128; // ケチ表現で省略された最上位ビットを復元

return std::ldexp(actual_mantissa, exponent - exponent_bias) * sign;
}
}

Expand Down

0 comments on commit d04db95

Please sign in to comment.