can explain me (in detail) how multiply 2 __int64 objs , check if result fit in __int64.
note: not use compiler or processor dependent routines.
not assuming a
, b
positive:
__int64 a,b; //... __int64 tmp_result = abs(a) * abs(b) ; if ( ( && b ) && ( ( tmp_result < abs(a) || tmp_result < abs(b) ) || ( tmp_result / abs(a) != abs(b)) || ( == type_min && b != 1) || ( b == type_min && != 1) ) ) std::cout << "overflow"; __int64 result = * b;
edit: adding corner cases code.
edit: in opinion ( && * b / != b)
enough.
Comments
Post a Comment