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

Re: Comparing Int and Num

Thread Previous | Thread Next
From:
sisyphus
Date:
April 28, 2021 06:09
Subject:
Re: Comparing Int and Num
Message ID:
CADZSBj0iB7D_Y0JZEFCKzTeP2hVyN=wT7+W7PVB_JProvi3mkA@mail.gmail.com
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

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