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

Re: Comparing Int and Num

Thread Previous | Thread Next
From:
Fernando Santagata
Date:
April 28, 2021 07:38
Subject:
Re: Comparing Int and Num
Message ID:
CAJ+jyGieMWtCcJoc7JmCy4YXus09deChc8kU2fDZH_934FvtGw@mail.gmail.com
Hi,
If you've found the Perl XS interface easy to work with, give Raku's
NativeCall a try, you will find it amazing. Since you already know the C
libraries, I guess you can cook an interface in no time.

On Wed, Apr 28, 2021 at 7:09 AM sisyphus <sisyphus359@gmail.com> wrote:

>
>
> On Tue, Apr 27, 2021 at 12:23 AM sisyphus <sisyphus359@gmail.com> wrote:
>
>
>> (I guess I could just use Inline::Perl5 ... not exactly my preferred
>> option ... but a viable alternative, I would think.)
>>
>>
> The following sort of works, but not in a very meaningful way.
> All it really does is show that perl is seeing the 3 raku variables ($n,
> $r1 and $r2) as being a 53-bit (double precision) representation of 0.1.
>
> use Math::GMPq:from<Perl5> ":mpq";
>
> --------------------------------------------------
> my $n = 1e-1;
> say "# ", Rmpq_get_str(Math::GMPq::new($n), 10);
>
> my Rat $r1 = 0.1;
> say "# ", Rmpq_get_str(Math::GMPq::new($r1), 10);
>
> my Rat $r2 = 1/10;
> ;
> say "# ", Rmpq_get_str(Math::GMPq::new($r2), 10);
>
> # Wanted:
> # 3602879701896397/36028797018963968
> # 1/10
> # 1/10
>
> # Got:
> # 3602879701896397/36028797018963968
> # 3602879701896397/36028797018963968
> # 3602879701896397/36028797018963968
>
> =finish
> use Devel::Peek:from<Perl5>;
> # Shows that perl sees $n, $r1, and $r2
> # as being the double 0.1:
> Devel::Peek::Dump($n);
> Devel::Peek::Dump($r1);
> Devel::Peek::Dump($r2);
>
> --------------------------------------------------
>
> Cheers,
> Rob
>


-- 
Fernando Santagata

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