From:

Date:

October 31, 2021 12:51Subject:

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

CADZSBj1YV6CC5H8LOVn4SukNdTJ22+0-JkjUVYO0TBQ_17TFjw@mail.gmail.comOn Sun, Oct 31, 2021 at 10:10 PM ToddAndMargo via perl6-users < perl6-users@perl.org> wrote: > On 10/31/21 01:43, Shlomi Fish wrote: > > > > >> ("" ~ sqrt(2)).comb().grep(* ne ".").map(+*) > > (1 4 1 4 2 1 3 5 6 2 3 7 3 0 9 5 1) > > Cool! > > my Int @x = ("" ~ sqrt(2)).comb().grep(* ne ".").map(+*) > [1 4 1 4 2 1 3 5 6 2 3 7 3 0 9 5 1] > > Is there a way to set how many digits I get? > In perl we can do: C:\>perl -e "@x = split(/\.|/, sqrt(2)); print for @x"; 14142135623731 C:\>perl -e "@x = split(/\.|/, sprintf('%.7g', sqrt(2))); print for @x"; 1414214 C:\>perl -e "@x = split(/\.|/, sprintf('%.8g', sqrt(2))); print for @x"; 14142136 But the same split() expression is unacceptable to Raku. Closest I could get with that approach: C:\>raku -e "say split(/\.|''/, sqrt 2);" ( 1 4 1 4 2 1 3 5 6 2 3 7 3 0 9 5 1 ) C:\_32>raku -e "say split(/\.|''/, sprintf('%.5g', sqrt 2));" ( 1 4 1 4 2 ) It's that additional space between the first 2 digits that has me beat. (I don't know raku at all.) Cheers, RobThread Previous | Thread Next

- how do I turn a real into and array of Integers? by ToddAndMargo via perl6-users
- Re: how do I turn a real into and array of Integers? by Andinus via perl6-users
- Re: how do I turn a real into and array of Integers? by Sean McAfee
- Re: how do I turn a real into and array of Integers? by ToddAndMargo via perl6-users
- Re: how do I turn a real into and array of Integers? by ToddAndMargo via perl6-users
- Re: how do I turn a real into and array of Integers? by Kevin Pye
- Re: how do I turn a real into and array of Integers? by ToddAndMargo via perl6-users
- Re: how do I turn a real into and array of Integers? by Sean McAfee
- Re: how do I turn a real into and array of Integers? by ToddAndMargo via perl6-users
- Re: how do I turn a real into and array of Integers? by sisyphus
- Re: how do I turn a real into and array of Integers? by Sean McAfee
- Re: how do I turn a real into and array of Integers? by Alice
- Re: how do I turn a real into and array of Integers? by Shlomi Fish
- Re: how do I turn a real into and array of Integers? by ToddAndMargo via perl6-users
- Re: how do I turn a real into and array of Integers? by Bruce Gray
**Re: how do I turn a real into and array of Integers?**by sisyphus- Re: how do I turn a real into and array of Integers? by William Michels via perl6-users
- Re: how do I turn a real into and array of Integers? by Patrick R. Michaud
- Re: how do I turn a real into and array of Integers? by William Michels via perl6-users
- Re: how do I turn a real into and array of Integers? by ToddAndMargo via perl6-users

nntp.perl.org: Perl Programming lists via nntp and http.

Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About