Closed axkr closed 2 years ago
What about adding a stream generator that would produce a Stream<BigFraction>
? This way, you could decide by yourself when to select the fraction you want using the Stream
API, for example with filter
and findFirst
.
What about adding a stream generator that would produce a
Stream<BigFraction>
? This way, you could decide by yourself when to select the fraction you want using theStream
API, for example withfilter
andfindFirst
.
That seems to be a good idea. Do you have an example how to do it?
I have added static methods convergents
in both Fraction
and BigFraction
to generate streams of fractions.
You can look at the unit tests to see how one specific convergent can be selected from the stream.
Beware that your criterion with a threshold of 10^c/d^2 will probably never be fulfilled. One theorem for errors bounds in continued fractions states that |α - pₖ/qₖ| < 1/(qₖqₖ₊₁). With this boundary, the numerator is 1 and not 10^c, and the denominator qₖqₖ₊₁ is bigger than qₖ^2 as the denominator series is an increasing series.
I have added static methods
convergents
in bothFraction
andBigFraction
to generate streams of fractions. You can look at the unit tests to see how one specific convergent can be selected from the stream.I also commented this on the commit: Shouldn't the spliterator created from the generatingIterator() also report the
ORDERED
characteristics, since the elements should not be arbitrarily reordered?Spliterator.DISTINCT | Spliterator.ORDERED
Maybe I don't understand this constructor correctly:
but what I'm looking for is a conversion where the result
n - numerator
andd - denominator
of thev - double value
satisfy the condition:with
c = -4
for example.