Fixed and simplified overflow checking
fixed negative number lookup for magnitude calculation
removed leftover testing variable
cast pointer to remove warning