Search This Blog

Saturday, August 22, 2020

Finding the largest number a computer can handle

I was helping my daughter Lulu learn programming (she was doing a Lua tutorial) and she asked a question about how big a number the program can handle. I said I don't know and recommended that we find out. We had lots of fun finding the answer.

I told her to try out a really big number. I said to put a 9, then the "to the power of" symbol, then a bunch of 9s. She picked something huge, far above the computer's limit. Then I recommended to try a much smaller number. That was too big. At some point I started suggesting numbers such that we were using Newton's Method to find the solution. 

The method is like this: 

  1. choose a high (overflow) and a low (no overflow). 
  2. cut difference in half. 
    1. if overflow, set that as the new high, else if no overflow, set that as the new low. 
      1. if happy with precision of the result, stop.
      2. Else, repeat from step 2. 
Lulu said that she's used this method before.

Here's a log of her work on this:

2+3

5

2+34

14

2394875324987532497859234875412

9.8668863389486346e+029

9^9

387420489

9^99

2.9512665430652752e+094

9^9999999999999999999999999999999

1/0 --[[math.huge]]

9^9999

1/0 --[[math.huge]]

9^999

1/0 --[[math.huge]]

9^998

1/0 --[[math.huge]]

9^100

2.6561398887587478e+095

9^500

1/0 --[[math.huge]]

9^102

2.1514733098945857e+097

9^250

3.6360291795869935e+238

9^350

1/0 --[[math.huge]]

9^300

1.873927703884794e+286

9^325

1/0 --[[math.huge]]

9^310

6.5339818865072468e+295

9^315

3.8582509641636642e+300

9^320

2.2782586118290021e+305

9^321

2.0504327506461019e+306

9^324

1/0 --[[math.huge]]

9^323

1.6608505280233425e+308

9^323.5

1/0 --[[math.huge]]

9^323.4

1/0 --[[math.huge]]

9^323.1

1/0 --[[math.huge]]

9^323.01

1.6977470088971238e+308

9^323.05

1/0 --[[math.huge]]

9^323.03

1.7740171916785718e+308

9^323.04

1/0 --[[math.huge]]

.9323.005

[string ".9323.005"]:1: malformed number near '.9323.005'

9^323.005

1.6791974321612211e+308

9^323.006

1.6828910624108526e+308

.9^323.010

1.6591015688607133e-015

No comments:

Post a Comment