[web-devel] haskell memory allocation
Henning Thielemann
lemming at henning-thielemann.de
Wed Sep 25 23:14:26 UTC 2019
On Thu, 26 Sep 2019, Henning Thielemann wrote:
> On Wed, 25 Sep 2019, anaaugusto2012 at bol.com.br wrote:
>
>> I want to allocate more memory because my teacher challenged me to show
>> him the first 12 and last 12 digits of the expression 2 ^ 17179869184
>
> Maybe better suited for haskell-cafe?
>
> I would be pretty waste of memory to compute the power completely.
>
> You can get the first 12 digits using approximate multiplications and you
> can get the last 12 digits using modulo arithmetic.
>
> It holds 17179869184 = 2^34.
>
> Prelude> mapM_ print $ take 35 $ iterate (\x -> let y = x*x in if y>=10 then
> y/10 else y) 2
> 2.0
> 4.0
> 1.6
> 2.5600000000000005
> ...
> 9.274368853264574
>
> That is, the first 12 digits should be 927436885326. Hopefully,
> computation was precise enough. If not, you might retry more precise
> computations using Integer.
Hm, computing with Integer gives a different result.
Computing with 25 decimal places gives me:
927436437019
for the first 12 digits and this does not change anymore when I increase
precision.
More information about the web-devel
mailing list