port sin/cos_pi_fmpq (with some tweaks)