a much more thorough fix for 64 bit number encoding
merged @pwmckenna's fix for 53bit numbers