02-27-2021, 07:35 AM
After reading the official Ruby 3.0.0 documentation I have discovered that there are 2 ways to get the square root of a number.
When working with small numbers, both options return the same results,
but when the numbers get bigger the results of Option 2 may be inaccurate as follows:
Option 1:
This will put exactly 100000000000000000000000 on the screen.
Option 2:
This will put 99999999999999991611392 on the screen.
When working with small numbers, both options return the same results,
but when the numbers get bigger the results of Option 2 may be inaccurate as follows:
Option 1:
Quote:Num1 = Integer.sqrt(10**46)
puts Num1
This will put exactly 100000000000000000000000 on the screen.
Option 2:
Quote:Num1 = Math.sqrt(10**46).floor
puts Num1
This will put 99999999999999991611392 on the screen.
Also follow me on Youtube for videos about video games:
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos