Skip to content

Instantly share code, notes, and snippets.

@mamantoha
Created April 16, 2016 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mamantoha/80083bcfc606dbf452ecb33603e73e0d to your computer and use it in GitHub Desktop.
Save mamantoha/80083bcfc606dbf452ecb33603e73e0d to your computer and use it in GitHub Desktop.
fi = Float::INFINITY
p = 1
p *= 2 while 2**p < fi
a = p/2
b = p
m = a/2
p = a + m
until (2**(p-1) != fi) && (2**p == fi)
m.zero? ? m = 1 : m = m/2
2**p == fi ? p -= m : p += m
end
print "Result: "
puts p - 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment