Math with Huge (infinite) numbers

require ‘bigdecimal’
=> 100000000000000.0. #wrong! Should be 9999999999999999

Puts x*x
=> 1.0e+32

Puts “%d” % (x*x)
=> 1000000000000009999999988654363748

I have been performing math with large numbers… This seems to be
limited by the hardware and operating system for what size a number can
be accurately processed… the example above shows at what point my
android device fails to provide accurate results…

are there any libs that can accurately process insanely large numbers?

Maybe Bigdecimal can but I’m using it wrong?

Puts Math.sqrt(999999)=> 999

So. I’m posting this example, I don’t understand the (16) part

I don’t see the benefit of using Bigdecimal… the output is not useful
for this… or I’m not doing something right…

On my labtop and on my android phone. I can perform sqrt at the most of
15 in length


Y is 16 bytes long and fails to show proper results.
I would like to perform math with even bigger numbers.

BigDecimal has its own #sqrt method.

When you define a bigdecimal number I highly suggest you use quotation

[32] pry(main)> x =“999999999999999999”)
=> #<BigDecimal:25e8df8,‘0.9999999999 99999999E18’,18(27)>
[33] pry(main)> (x*x).sqrt(20).to_i
=> 999999999999999999