How do I avoid scientific notation for large numbers?

后端 未结 8 1181
Happy的楠姐
Happy的楠姐 2020-12-15 05:04

I am doing 2^1000 and I am getting this:

1.07151e+301

Is there any way to actually turn this into a proper number without the e+301, or at least can anyone s

8条回答
  •  爱一瞬间的悲伤
    2020-12-15 05:32

    You need to use a number class specifically designed for long numbers.

    To represent 2^1000 as an exact number then by definition you need a number format that actually holds 1001 binary bits. The longest normal primitive integer format is usually only 64 bits.

    BTW, the answer is:

    % perl -Mbigint -e 'print 2**1000'
    10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376
    

提交回复
热议问题