From d04db955fe27df768014ecc8146d94dfc274d3bb Mon Sep 17 00:00:00 2001 From: yutotnh <57719497+yutotnh@users.noreply.github.com> Date: Mon, 7 Aug 2023 21:19:55 +0900 Subject: [PATCH] =?UTF-8?q?style:=20=E4=BB=AE=E6=95=B0=E9=83=A8=E3=81=AE?= =?UTF-8?q?=E3=81=91=E3=81=A1=E8=A1=A8=E7=8F=BE=E3=81=BE=E3=82=8F=E3=82=8A?= =?UTF-8?q?=E3=81=AE=E5=87=A6=E7=90=86=E3=82=92=E3=82=8F=E3=81=8B=E3=82=8A?= =?UTF-8?q?=E3=82=84=E3=81=99=E3=81=84=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/spirit/src/bfloat16.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/spirit/src/bfloat16.cpp b/src/spirit/src/bfloat16.cpp index d025cc1..9ddbc70 100644 --- a/src/spirit/src/bfloat16.cpp +++ b/src/spirit/src/bfloat16.cpp @@ -25,8 +25,10 @@ float bfloat16_to_float32(const uint16_t bfloat16) return std::numeric_limits::quiet_NaN() * sign; } } else { - constexpr uint32_t exponent_bias = 127 + 7; // 128: 指数部の0x7Fのオフセット, 7: 仮数部のビット数 - return std::ldexp(static_cast(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; } }