Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^12: Introspection into floats/NV

by ikegami (Patriarch)
on Jun 04, 2025 at 21:42 UTC ( [id://11165262]=note: print w/replies, xml ) Need Help??


in reply to Re^11: Introspection into floats/NV
in thread Introspection into floats/NV

A completely different question is whether the generated content is really one hundred percent wrong.

The readers can judge for themselves if your post with the incorrect bits removed tells them the difference between d and F.

Perl `pack` Template Comparison: "d" vs "F" =========================================== Summary Table ------------- | Template | Type | Precision | Bits | Description + | |----------|--------|--------------|------|--------------------------- +---------| | "d" | double | XXXXXXXXXXXX | XX | XXXXXXXXXXXXXXXXXXXXXXXXXX +XXXXX | | "F" | XXXXXX | XXXXXXXXXXXX | XX | XXXXXXXXXXXXXXXXXXXXXXXXXX +XXXXX | Example Code ------------ use feature 'say'; my $x = 1/3; say "Xouble:"; say unpack("BXX", pack("d>", $x)); # Big-endian XXXXXX say "XXXXX:"; say unpack("BXX", pack("F>", $x)); # Big-endian XXXXX Difference Illustration ----------------------- my $x = 1/3; my $XXXXX_bin = unpack "BXX", pack "F>", $x; my $double_bin = unpack "BXX", pack "d>", $x; printf " XXXXX (XX-bit): %s\n", $XXXXX_bin; printf "Xouble (XX-bit): %s\n", $double_bin; Expected Output: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +XXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +XXXXXXXXXXXX IEEE 754 Format Summary ----------------------- | Precision | Sign | Exponent | Mantissa (Significand) | Bias | |-----------|------|----------|-------------------------|------| | XXXXX | 1 bit | 8 bits | 23 bits | 127 | | Double | 1 bit | 11 bits | 52 bits | 1023 | Usage Notes ----------- - Use "d" / "d>" if you want: - XXXXXXXXXXXXXXXX - XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - Direct compatibility with XXXXXXXXXXXXXXXXXXXXXXXX - Use "F" / "F>" if you want: - XXXXXXXXXXXXXXXXXXX - Exact compatibility with XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Endianness Reminder ------------------- - d> and F> -> big-endian - d< and F< -> little-endian - d and F (no angle) -> native-endian (machine dependent)

(Formatting errors left in. Only substantive errors were removed.)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2025-07-11 01:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.