Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: [perl6] More Inline::Perl5 musings

by duelafn (Vicar)
on Mar 17, 2016 at 16:28 UTC ( #1158122=note: print w/replies, xml ) Need Help??

in reply to [perl6] More Inline::Perl5 musings

The Perl6 Spec allows for native num128, but MoarVM seems to only support native 32 and 64-bit nums (It's unclear to me how to actually reach the "long double" case). Eventually one should be able to do this:

# Not yet: $ perl6 -e 'my num128 $one = Num(1); $one += 1e-30; say $one == 1' False

I have no idea or intuition for how hard it might be to get num128 to work in MoarVM, but apparently num128 isn't on the roadmap for the near future.

In response to Tux (who probably already knows this), Perl6 Rats are great for general-purpose computing (and completely awesome in financial software), but only higher precision will do for numerical simulation. Until we have num128, there is value to Math::Float128:

$ perl6 -e 'my $one = 1; $one += 1e-16; say $one == 1' True $ perl6 -e 'say pi ** 621' Inf $ perl6 -e 'say sin(pi/2).WHAT' (Num) $ perl6 -e 'my $val = sin(pi/2) + 0.1; my $eleven = 0; $eleven += $val + for 1..10; say $eleven == 11' False

Good Day,

Replies are listed 'Best First'.
Re^2: [perl6] More Inline::Perl5 musings
by syphilis (Bishop) on Mar 18, 2016 at 11:13 UTC
    Thanks Corion, Tux, duelafn.
    Not much to add except that the level of support for perl5 extensions seems pretty good.

    In general, I haven't yet found a way to access overloaded operators directly.
    Instead I'm calling the overloading subroutines by name - eg:
    use Inline::Perl5; my $p5 =; $p5.use('Math::Float128'); my $f1 = $p5.invoke('Math::Float128', 'new', '2.5'); my $f2 = $p5.invoke('Math::Float128', 'new', '3.0'); my $swap = 0; # Set to true if order of # operands is to be swapped # Set $f3 to $f1 divided by $f2 my $f3 = $f1._overload_div($f2, $swap); say "# $f3"; # Outputs, as expected: # 8.33333333333333333333333333333333365e-01
    I was hoping to be able to do something like:
    my $f3 = $f1 / $f2;
    but that doesn't work, so I have to resort to calling Math::Float128::_overload_div() by name.

    That's no big deal, but it still puzzles me that say "# $f3"; apparently manages to access the Math::Float128 overloading of "" without any need for me to call Math::Float128::_overload_string() by name.
    Yet for all other overloaded operators I'm having to call the relevant subroutine.
    The penny will drop when it's ready to fall ;-)

    I'm also wondering whether Inline::Perl5 will work on MS Windows. Any experience of that here ?
    I think it should be ok:
    C:\>perl -V:useshrplib useshrplib='true';

    At some stage I'll grab a Windows version of perl6 ... and find out ...


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1158122]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2021-03-04 21:55 GMT
Find Nodes?
    Voting Booth?
    My favorite kind of desktop background is:

    Results (108 votes). Check out past polls.