Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: 仮数部のけち表現まわりの処理をわかりやすいように修正 #262

Merged
merged 2 commits into from
Aug 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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