Perl6 precision base4 conversion

Perl 6 loses accuracy when converting to / from base4. How to maintain accuracy?

'0.2322130120323232322110'.parse-base(4)
--> perl6 output :         0.728295262649453
--> high precission value: 0.728295262649453434278257191181182861328125

The problem is that when converting 0.728295262649453to base(4)output is not the original number.

0.72829526264945.base(4)
--> output:   0.232213012032323232210333
--> original: 0.2322130120323232322110

Please explain to me how to get the same values ​​after / from a conversion?

+4
source share
1 answer

The problem is probably how you created your "perl6 output":

say "0.2322130120323232322110".parse-base(4)    # 0.72829526264945

This is because the saymethod is called .gistfor what is given to it. Or you tried to compress it (which causes .Str, which gives the same result as .gist). If you call the method .perlon the result:

say "0.2322130120323232322110".parse-base(4).perl

0.728295262649453434278257191181182861328125. .perl , EVAL .

, :

say "0.2322130120323232322110".parse-base(4).base(4)

, 0.2322130120323232322110. , , .: -)

, .Str a Rat .perl .gist. , : , .

+7

Source: https://habr.com/ru/post/1684995/


All Articles