mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-12 03:39:01 +08:00
Fix half_impl::float_to_half_rtne(float) warning: '<<' causes overflow
Fixed Visual Studio 2019 Code Analysis (C++ Core Guidelines) warning C26450 from inside `half_impl::float_to_half_rtne(float)`: > Arithmetic overflow: '<<' operation causes overflow at compile time.
This commit is contained in:
parent
35d149e34c
commit
5328c9be43
@ -472,7 +472,9 @@ EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC __half_raw float_to_half_rtne(float ff) {
|
|||||||
unsigned int mant_odd = (f.u >> 13) & 1; // resulting mantissa is odd
|
unsigned int mant_odd = (f.u >> 13) & 1; // resulting mantissa is odd
|
||||||
|
|
||||||
// update exponent, rounding bias part 1
|
// update exponent, rounding bias part 1
|
||||||
f.u += ((unsigned int)(15 - 127) << 23) + 0xfff;
|
// Equivalent to `f.u += ((unsigned int)(15 - 127) << 23) + 0xfff`, but
|
||||||
|
// without arithmetic overflow.
|
||||||
|
f.u += 0xc8000fffU;
|
||||||
// rounding bias part 2
|
// rounding bias part 2
|
||||||
f.u += mant_odd;
|
f.u += mant_odd;
|
||||||
// take the bits!
|
// take the bits!
|
||||||
|
Loading…
x
Reference in New Issue
Block a user