fix upcasting negative values. Closes bug #24