maths: fix hi-lo normalisation shift size
This commit is contained in:
parent
0369b16f73
commit
ac86ef3bd5
@ -446,6 +446,9 @@ typename std::enable_if<
|
|||||||
>::type
|
>::type
|
||||||
renormalise [[gnu::pure]] (T t)
|
renormalise [[gnu::pure]] (T t)
|
||||||
{
|
{
|
||||||
|
static_assert (sizeof (T) > sizeof (U),
|
||||||
|
"assumes right shift is sufficient");
|
||||||
|
|
||||||
// we have excess bits ,just shift and return
|
// we have excess bits ,just shift and return
|
||||||
constexpr auto shift = 8 * (sizeof (T) - sizeof (U));
|
constexpr auto shift = 8 * (sizeof (T) - sizeof (U));
|
||||||
return t >> shift;
|
return t >> shift;
|
||||||
@ -462,6 +465,9 @@ typename std::enable_if<
|
|||||||
>::type
|
>::type
|
||||||
renormalise [[gnu::pure]] (T t)
|
renormalise [[gnu::pure]] (T t)
|
||||||
{
|
{
|
||||||
|
static_assert (sizeof (T) < sizeof (U),
|
||||||
|
"assumes bit creation is required to fill space");
|
||||||
|
|
||||||
// we need to create bits. fill the output integer with copies of ourself.
|
// we need to create bits. fill the output integer with copies of ourself.
|
||||||
// this is approximately correct in the general case (introducing a small
|
// this is approximately correct in the general case (introducing a small
|
||||||
// linear positive bias), but allows us to fill the output space in the
|
// linear positive bias), but allows us to fill the output space in the
|
||||||
@ -473,7 +479,7 @@ renormalise [[gnu::pure]] (T t)
|
|||||||
U out = 0;
|
U out = 0;
|
||||||
|
|
||||||
for (size_t i = 0; i < sizeof (U) / sizeof (T); ++i)
|
for (size_t i = 0; i < sizeof (U) / sizeof (T); ++i)
|
||||||
out |= t << sizeof (U) * 8 * i;
|
out |= U (t) << sizeof (T) * 8 * i;
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user