Use a 32 bit int (i.e. T_IV or T_UV) which has the advantage that any numbers in the 32 bit range can be accurately be represented,

Note that this is not an advantage over NV (floating point). A Perl NV can exactly represent any 52-bit integer (53 if you count the sign bit) on almost any platform (I think even Crays use standard IEEE 8-byte double-precision floating point numbers). 52-bit values often are quite sufficient for such situations (address 4 peta bytes or store 142 years in microseconds).

But if you really want to allow for full 64-bit values, my first idea was also to use a string of digits for the representation. That is probably the best choice for an XS interface, as it will conveniently and silently allow the user to switch to NV or IV if they don't need values that won't fit in such a type (or don't need full precision for some values in the case of NV).

But doing this right will be a little tricky. In particular, you'll need to pay attention to what value types the scalar passed to you has, and which of those value type(s) is/are primary. Perhaps use the scalar's NV if SvNOK() [not SvNOKp()] or not SvPOK(), otherwise use the scalar's PV [if SvPOK() but not SvNOK()].

- tye        


In reply to Re^2: Supporting long long types in XS (NV,PV) by tye
in thread Supporting long long types in XS by chrisdolan

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.