Created
June 8, 2021 05:20
-
-
Save havenwood/c0449fb7e37c244e09ff54addb47d4b5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# When Math.sqrt(2).fdiv(2) is just too zippy. | |
require 'bigdecimal' | |
require 'bigdecimal/util' | |
def i_ish(precision:) | |
sqrt_2 = 2.to_d.sqrt precision | |
sqrt_i = Complex sqrt_2 / 2, sqrt_2 / 2 | |
sqrt_i * sqrt_i | |
end | |
0.step do |n| | |
imaginary = i_ish(precision: n).imaginary | |
nines = imaginary.to_digits.delete_prefix('0.')[/\A9*/] | |
puts "2.to_d.sqrt(#{n}) nines: #{nines.size}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment