Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Incrementing "Infinity" bug

by kcott (Bishop)
on Mar 25, 2013 at 06:28 UTC ( #1025232=note: print w/replies, xml ) Need Help??


in reply to Incrementing "Infinity" bug

G'day Rolf,

"tested in 5.10

could someone plz test in newer versions and reply?"

Same result in 5.14.2:

$ perl -e '$a=inf; print ++$a,"\n"' ing $ perl -v This is perl 5, version 14, subversion 2 (v5.14.2) built for darwin-th +read-multi-2level

As you were probably aware, warnings alert you and strictures disallow it altogether:

$ perl -Mwarnings -e '$a=inf; print ++$a,"\n"' Unquoted string "inf" may clash with future reserved word at -e line 1 +. ing $ perl -Mstrict -e '$a=inf; print ++$a,"\n"' Bareword "inf" not allowed while "strict subs" in use at -e line 1. Execution of -e aborted due to compilation errors.

-- Ken

Replies are listed 'Best First'.
Re^2: Incrementing "Infinity" bug
by LanX (Archbishop) on Mar 25, 2013 at 12:16 UTC
    Hi Ken!

    > As you were probably aware, warnings alert you and strictures disallow it altogether:

    Yes, I became aware after posting the first time.

    I expected inf and it's brothers▓ to be constants because of their magic behavior when being numified.

    Introducing constants╣ for inf, -inf and NaN (even all uppercase like INF) would help clarifying the situation.

    Cheers Rolf

    ( addicted to the Perl Programming Language)

    ╣) like I demonstrated here

    ▓) every string starting with inf (no matter if upper or lower case) numifies to inf:

    DB<106> $a="Infinity"+0 => "inf" DB<109> $a="Inftyddssssd"+0 => "inf" DB<110> $a="Inf"+0 => "inf" DB<111> $a="InF"+0 => "inf"

    UPDATE: line 109 with"Inftyddssssd" fails with activated warnings, anything else with lc($else) ~~ ['inf','infinity'] won't

    DB<123> use warnings; $a='InFiNiTy'+0 => "inf" DB<125> use warnings;$a="Inftyddssssd"+0 Argument "Inftyddssssd" isn't numeric in addition (+) at (eval 74)[mul +ti_perl5db.pl:644] line 2.

      I came across Inf (and friends) some years ago, decided they all looked somewhat flakey, and haven't used them since. Your posting has (somewhat) piqued my interest again. Here's some interesting results from Scalar::Util's looks_like_number() function.

      $ perl -E ' use Scalar::Util qw{looks_like_number}; my @infs = (inf, Inf, INF, infinity, Infinity, INFINITY, -inf, -Inf, -INF, -infinity, -Infinity, -INFINITY, Inftyddssssd, infighting, Infighting, -Inftyddssssd, -infighting, -Infighting); say "$_ : ", looks_like_number($_) for @infs; ' inf : 20 Inf : 20 INF : 20 infinity : 20 Infinity : 20 INFINITY : 20 -inf : 28 -inf : 28 -inf : 28 -inf : 28 -inf : 28 -inf : 28 Inftyddssssd : 0 infighting : 0 Infighting : 0 -Inftyddssssd : 0 -infighting : 0 -Infighting : 0

      I also noted that the documentation for this function links to perlapi - looks_like_number, which may be of interest ot you.

      -- Ken

        I suppose these numbers reflect some flags?

        something like:

        2^3 for negative

        2^2 for special value

        2^4 for infinity

        couldn't find explanation in the docs.

        > decided they all looked somewhat flakey,

        agreed, but shouldn't we try to fix it.

        Don't you think the algorithm I used is a valid use case? (non-reachable integer)

        Cheers Rolf

        ( addicted to the Perl Programming Language)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2019-11-11 22:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (63 votes). Check out past polls.

    Notices?