port the last of gamma_fmpq and add test code