Python Forum
Periodic Fractions with Fraction or float_to_ratio?
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Periodic Fractions with Fraction or float_to_ratio?
#1
Hey there,
having little trouble with some numbers.
Wanna convert 205/144 (which is as float: 1.4236111111...) into its fraction 205/144.
This is possible with Fraction or float_to_ratio, like its mentioned here: https://stackoverflow.com/questions/2334...o-fraction
But how can I convert periodic (or partially periodic) numbers in those fractions?
It's really important, that I get 205/144 from 1.42361111111..., because I wanna calculate some Wolstenholme numbers.

Best wishes,
TimeMen
Reply
#2
The link gives the exact recipe - which you are obviously too lazy to try Angry
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply
#3
@volcano63
I know about using .limit_denominator(), but how do I have to choose it's argument?
If I use Fraction(1.4236111111111112).limit_denominator(200) I get the right result.
But what if I don't know the argument 200?
Reply
#4
Reference: https://docs.python.org/3/library/fractions.html
The default maximum value limit_denominator is 1,000,000. If you want a maximum value of the denominator less than that, you have to arbitrarily guess what you want the maximum denominator to be.

Lewis
To paraphrase: 'Throw out your dead' code. https://www.youtube.com/watch?v=grbSQ6O6kbs Forward to 1:00
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Plotting periodic function with fft schniefen 0 1,026 Nov-10-2022, 11:53 AM
Last Post: schniefen
  Sum Series w/ Fractions EwH006 12 13,529 Oct-11-2016, 06:47 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020