Just curious, not a 'problem' which requires solution. Maybe developers thought real numbers stringification is usually approximate, that's why? Or simply nobody cares?
C:\>perl -MDevel::Peek -e "$x = 0.5; qq/$x/; Dump $x"
SV = PVNV(0x38bb4) at 0xd217cc
REFCNT = 1
FLAGS = (NOK,pNOK)
IV = 0
NV = 0.5
PV = 0xd16014 "0.5"\0
CUR = 3
LEN = 28
C:\>perl -MDevel::Peek -e "$x = 0; qq/$x/; Dump $x"
SV = PVIV(0xd200c4) at 0xd2685c
REFCNT = 1
FLAGS = (IOK,POK,pIOK,pPOK)
IV = 0
PV = 0xd16274 "0"\0
CUR = 1
LEN = 10
Hence, 'double' is converted to string any time it is required. E.g.:
use Benchmark qw/ cmpthese /;
$x = 42.0;
%h = ();
cmpthese( -1, {
F => sub { $h{ pack 'F', $x } = 1 },
s => sub { $h{ $x } = 1 },
});
Rate s F
s 344025/s -- -86%
F 2490475/s 624% --
I found that one my little application, which maintains kind of 'seen' hash, gets nice boost if hash keys are packed as above, instead of 'just used as they are'. Actually, keys are pixels coordinates, they became real numbers because library I use returns them so. Pixels are usually aplenty and hash is accessed a lot, therefore speed gain was significant. But of course it would be even faster if PV was added on first access and POK was set, i.e. without packing.
-
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.