Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Incrementing "Infinity" bug (numification, perlnumber, magic increment decrement)

by Anonymous Monk
on Mar 24, 2013 at 22:30 UTC ( #1025191=note: print w/ replies, xml ) Need Help??


in reply to Incrementing "Infinity" bug

This is not a bug

Perl has magic increment operator, it works on strings

Perl not have magic decrement operator, so string is turned into a number

inf looks like a string so it is a string, not a number, use int to force numification

$ perl -MData::Dump -e " $f = inf; dd $f; $f--; dd $f; " "inf" 1.#INF $ perl -MData::Dump -e " dd int inf " 1.#INF $ perl -MData::Dump -e " dd int Infinity " 1.#INF

perlnumber, perldata, 2010 :) Infinity and Inf?


Comment on Re: Incrementing "Infinity" bug (numification, perlnumber, magic increment decrement)
Download Code
Re^2: Incrementing "Infinity" bug (numification, perlnumber, magic increment decrement)
by LanX (Canon) on Mar 24, 2013 at 23:20 UTC
    It's a bug or at least a design flow.

    Creating a constant which returns a numified inf easily fixes this problem

    DB<100> use constant inf => inf+0 => 0 DB<101> $a=inf => "inf" DB<102> ++$a => "inf" DB<103> ++$a => "inf"

    So why doesn't Perl do this per default?

    do we really need to use hacks like 1e9999 to create inf?

    Cheers Rolf

    ( addicted to the Perl Programming Language)

      It's a bug or at least a design flow.

      How do you figure? I think it isn't

      So why doesn't Perl do this per default?

      You know why, tradition (backwards compatibility ). "barewords" have always been strings

      Also style, lowercase constants are unbecoming :p

      do we really need to use hacks like 1e9999 to create inf?

      We never needed that, use  0+'inf' or  int '-inf' ...

      But hey, one of the math modules could export ... or even  use feature 'infinity'; could happen though I don't see the benefit, but what do I know

      $ perl -le " for(1..4){ print for \int 'infinity', \int'-infinity' } +" SCALAR(0x99bc74) SCALAR(0x99bc64) SCALAR(0x99bc74) SCALAR(0x99bc64) SCALAR(0x99bc74) SCALAR(0x99bc64) SCALAR(0x99bc74) SCALAR(0x99bc64)

      update: nans, infs, and vomit, How to create nan/inf says bigint/bigrat export inf that stringifies to inf

      Also note Re^3: nans, infs, and vomit (underlying c-runtime and strtod, atof)

        > We never needed that,

        I showed a use case producing short, self-explanatory code with the use of inf.

        > use 0+inf or int '-inf' ...

        sure, why not introducing one more level of cryptic workarounds to justify perl's reputation of a line-noise-language instead of having self explanatory constants?

        > update:

        well ... no comment on the fact of an AnoMonk who can update his nodes ...;-)

        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://1025191]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2014-09-17 06:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (60 votes), past polls