On Thu, 14 May 2020, ToddAndMargo via perl6-users wrote:
> Hi All,
> 
> 1) how do I get 40 or more digits out of sqrt?
> 

Meaningful digits? Not possible as sqrt uses limited precision. I think
the IEEE 754 doubles that I would suspect to be used internally are capped
way below 40 significant decimal digits.

> 2) how to I assist those bytes to a 40 (or more)
> byte long Buf?
> 
> This obviously does not work:
> 
> my Num $x = 3.sqrt; my Buf $y = Buf.new($x)
> 
> Type check failed in initializing element #0 to Buf; expected uint8 but got
> Num (1.7320508075688772e0)
>   in block <unit> at <unknown file> line 1
> 

You can convert the Num to a string and put that string into a Buf:

  Buf.new(3.sqrt.Str.encode)

That's what I'd do without any clue at all about who is supposed to use
this Buf. At least the buffer is about as long as the number is decimal
digits, which seems to be what you wanted?

Regards,
Tobias

Reply via email to