The Continued fraction algorithm is not implemented
Closed this issue · 1 comments
itsubaki commented
Lines 5 to 22 in f82f9cf
func Fraction(f float64, eps float64) ([]int, int, int) { | |
continued := make([]int, 0) | |
reciprocal := f | |
for { | |
continued = append(continued, int(reciprocal)) | |
diff := reciprocal - math.Trunc(reciprocal) | |
if diff < eps { | |
break | |
} | |
reciprocal = 1.0 / diff | |
} | |
// TODO return numerator denominator | |
return continued, 3, 7 | |
} |
itsubaki commented
Lines 7 to 31 in ca827f7
func Fraction(f float64, eps float64) ([]int, int, int) { | |
list := make([]int, 0) | |
reciprocal := f | |
for { | |
list = append(list, int(reciprocal)) | |
diff := reciprocal - math.Trunc(reciprocal) | |
if diff < eps { | |
break | |
} | |
reciprocal = 1.0 / diff | |
} | |
if len(list) == 1 { | |
return list, 1, list[0] | |
} | |
n, d := 1, list[len(list)-1] | |
for i := 2; i < len(list); i++ { | |
n, d = d, list[len(list)-i]*d+n | |
} | |
return list, n, d | |
} |