Bonita Montero
unread,May 7, 2021, 5:11:26 AM5/7/21You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
>> bool signChange = ((left + right) ^ left) >> 31;
> This is presumably missing the casts to uint32_t. As it stands, you
> have a recursive loop.
No, the values should remain signeds to result -1 or 0,
converted to truw or fase.
>> bool carry = (uint32_t)left + (uint32_t)right <
>> (uint32_t)left;
>> bool overflow = signChange & !carry;
>> if( overflow )
>> throw range_error( "bint32_t add-overflow" );
>> return left.m_value + right.m_value;
>> }
>
> The class you gave earlier was buint32_t, with the underlying type being
> unsigned (uint32_t). Now you have switched to bint32_t, but it is not
> clear if your underlying arithmetic is done using signed or unsigned types.
I just wanted to give an exampe how a oveflow-test would look like
for a signed version of my class.