display as fraction

This commit is contained in:
filifa 2025-08-18 23:50:19 -04:00
parent f5d0ff1e61
commit 385e2f4a80
1 changed files with 7 additions and 2 deletions

View File

@ -54,16 +54,21 @@ func convergents(cmd *cobra.Command, args []string) {
seq(h, hprev, a0) seq(h, hprev, a0)
seq(k, kprev, a0) seq(k, kprev, a0)
fmt.Println(h, k)
r := new(big.Rat).SetFrac(h, k)
fmt.Println(r)
for i := 0; true; i = (i + 1) % len(denoms) { for i := 0; true; i = (i + 1) % len(denoms) {
a := &denoms[i] a := &denoms[i]
seq(h, hprev, a) seq(h, hprev, a)
seq(k, kprev, a) seq(k, kprev, a)
fmt.Println(h, k)
r.SetFrac(h, k)
fmt.Println(r)
} }
} }
// FIXME: should support an initial block of non-periodic denominators (will need flags)
// convergentsCmd represents the convergents command // convergentsCmd represents the convergents command
var convergentsCmd = &cobra.Command{ var convergentsCmd = &cobra.Command{
Use: "convergents N N [N ...]", Use: "convergents N N [N ...]",