develooper Front page | perl.perl6.users | Postings from November 2021

Re: how do I turn a real into and array of Integers?

Thread Previous | Thread Next
From:
Sean McAfee
Date:
November 1, 2021 16:17
Subject:
Re: how do I turn a real into and array of Integers?
Message ID:
CANan03ZvY35bKEXS2k8wT-FdhfG9qATr7eKYPF8NMVAQL5SzOw@mail.gmail.com
On Mon, Nov 1, 2021 at 1:53 AM sisyphus <sisyphus359@gmail.com> wrote:

> Note that what you have there is a 200-decimal-digit (around 658-bit)
> precision representation of the square root of 2 - which is quite different
> to the (53-bit precision) Real  sqrt(2).
>

Always gotta be careful with reals.  I also attempted to get the digits of
the real square root of 2 using a numeric-only method:

    (2.sqrt, { 10 * ($_ - .truncate) } ...^ 0)>>.truncate

This gives:

    (1 4 1 4 2 1 3 5 6 2 3 7 3 0 9 5 1 0 1 0 6 5 7 0 0 8 7 3 7 3 2 5 6 6 8
3 3 4 9 6 0 9 3 7 5)

That's a lot more digits than you see in the string representation of
2.sqrt, but checking showed that most of them--all of them after the
7-3-0-9-5---are wrong.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About