On Wed, Dec 21, 2016 at 1:11 PM, Gerald Magnuson
<gmagqcy.midrange@xxxxxxxxx> wrote:
That question (what about "non clean" fractions) has not yet been
answered...
the initial response was "that doesn't happen"... ;)
The moment you count on it not happening, it will.
Building a table is probably the best bet, if you only need it to be
accurate to .01 or so. It's not like anybody is ever going to ask for
a fractional approximation of pi accurate to four or five decimal
places. It'd be a cool routine, though, if it could return fractions
accurate to a desired amount.
Valid values for pi would be:
3/1
22/7
333/106
355/113
103993/33102 and so on. As pi is transcendental, we never get there.
The code is actually not that difficult; you just use continuing
fractions (
https://en.wikipedia.org/wiki/Continued_fraction#Best_rational_approximations)
Can't think of much of a business use, but I'm pretty sure I've got
most of the code already written. If I have a slow afternoon over the
holidays, I'll wrap it up in service program:
returnFraction( decimalValue : accuracy : numerator : denominator )
and post a link.
Easy to test; if you run it for phi (the golden mean) your numerator
and denominator will always be adjacent Fibonacci numbers.
Chris
www.brilligware.com - Home of MineSweeper5250
On Wed, Dec 21, 2016 at 1:03 PM, Paul Therrien <
paultherrien@xxxxxxxxxxxxxxxxxx> wrote:
I am curious. Are the numbers coming in always going to result in clean
fractions?
What would be the resulting fraction if the incoming number was 0.03126?
1/31.98976; 1/31.99?; 1/32?
Depending upon the desired level of accuracy:
1/31
1/32
97/3103
98/3135
293/9373
1563/50000
The last one, of course, is exact.
---
Chris
www.brilligware.com - Home of MineSweeper5250
As an Amazon Associate we earn from qualifying purchases.