What programming language will enable me to enter a very long number without converting it to floating point?

后端 未结 14 833
情书的邮戳
情书的邮戳 2020-12-11 21:17

What would be the best way to do the following.

Enter a very long number, lets say 500,000 digits long without it going into scientific notation; and then am able to

14条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-11 21:26

    Haskell (when using GHC) also has builtin support for arbitrarily long integers. Here's a snippet showing the length of a number converted to a string.

    Prelude> length $ show $ 10
    2
    Prelude> length $ show $ 1 + 2^2000000
    602060
    Prelude> let x = 2^200000
    Prelude> let y = 2^200000 + 5
    Prelude> y - x
    5
    

    Or you could just type 2^200000 at the interactive console and wait a couple minutes for it to print out all 600k+ characters. I figured this way was a little simpler to demonstrate.

提交回复
热议问题