Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Can you see any bugs?

In perl, strings like "2e5" and "1E4" are valid integer strings.
Are they being handled as you would like ? (I haven't investigated, and it depends upon how you want them to be treated.)

If you want to accept them then you also have to keep in mind that if they represent values greater than ~0 or less than -(~0 >> 1) then they'll be assigned to NVs (floating point values) rather than IVs (integer value).

I guess it's probably simplest if you reject them.

Update, correcting an earlier incorrect update: After I wrote this post I discovered that if you assign a value like 2e5 as a bareword, you get an NV, not an IV - and I therefore thought I had made a mistake in asserting that such strings were "integer strings".
However, although the barewords often assign as an NV, the above assertions seem to be correct in relation to numifying strings.
It seems a bit random.
We get an NV with:
C:\>perl -MDevel::Peek -le "$x = 1e6; Dump $x;" SV = NV(0x488470) at 0x488488 REFCNT = 1 FLAGS = (NOK,pNOK) NV = 1000000
but an IV if we perform some arithmetic function:
C:\>perl -MDevel::Peek -le "$x = 1e6 * 1.0; Dump $x;" SV = IV(0x4ecb10) at 0x4ecb20 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 1000000
and, as regards what I've written above, if we numify the string we still get an IV:
C:\>perl -MDevel::Peek -le "$x = '1e6' * 1.0; Dump $x;" SV = IV(0x33d010) at 0x33d020 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 1000000
unless the value represented by the string is outside of the IV range:
C:\>perl -MDevel::Peek -le "$x = '1e70' * 1.0; Dump $x;" SV = NV(0x576440) at 0x576458 REFCNT = 1 FLAGS = (NOK,pNOK) NV = 1e+70

Cheers,
Rob

In reply to Re^9: Reliably parsing an integer by syphilis
in thread Reliably parsing an integer by rdiez

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (3)
As of 2024-04-19 22:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found