Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Calculate the fixed point of cosine in Ruby.
TOLERANCE = 0.00000000000000000001
def tolerance_equals?(a, b)
((a - b) * (a - b)) < TOLERANCE
def recursive_cosine_fixedpoint(a)
return a if tolerance_equals?(a, Math.cos(a))
puts "The fixed point of cosine is #{recursive_cosine_fixedpoint(1)}"
# The fixed point of cosine is 0.7390851331706995
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.