andreas1234567 points out that using Math::BigFloat to recover the moniker for infinity may not jive with the perl internal for infinity. This was indeed an error on my part. I should have realized that Math::BigFloat might not have been compiled against the same library as Perl. Here is the demonstration from andreas1234567:

#!perl use strict; use warnings; use Config; use Math::BigFloat; print qq{Perl $], $^X, archname=$Config{archname}, byteorder=$Config{b +yteorder} }; my $le = ( $Config{byteorder} =~ qr/^1234/ ) ? 1 : 0; use constant POSITIVE_INFINITY => "\x7f\xf0\x00\x00\x00\x00\x00\x00"; use constant NEGATIVE_INFINITY => "\xff\xf0\x00\x00\x00\x00\x00\x00"; use constant NOT_A_NUMBER => "\x7f\xf8\x00\x00\x00\x00\x00\x00"; # manually if ($le) { print qq{le:} .unpack("d*", reverse POSITIVE_INFINITY); print qq{le:} .unpack("d*", reverse NEGATIVE_INFINITY); print qq{le:} .unpack("d*", reverse NOT_A_NUMBER); } else { print qq{be:} .unpack("d*", POSITIVE_INFINITY); print qq{be:} .unpack("d*", NEGATIVE_INFINITY); print qq{be:} .unpack("d*", NOT_A_NUMBER); } # using Math::BigFloat print qq{mbf:} .Math::BigFloat->binf(); print qq{mbf:} .Math::BigFloat->binf('-'); print qq{mbf:} .Math::BigFloat->bnan(); __END__ # MSWin32 C:\src\perl\infinity>perl -wl infinity.pl Perl 5.008008, C:\Perl\bin\perl.exe, archname=MSWin32-x86-multi-thread +, byteorder=1234 le:1.#INF le:-1.#INF le:1.#QNAN mbf:inf mbf:-inf mbf:NaN # darwin $ perl -wl infinity.pl Perl 5.008006, perl, archname=darwin-thread-multi-2level, byteorder=43 +21 be:inf be:-inf be:nan mbf:inf mbf:-inf mbf:NaN # i386-linux Perl 5.008005, /usr/bin/perl, archname=i386-linux-thread-multi, byteor +der=1234 le:inf le:-inf le:nan mbf:inf mbf:-inf mbf:NaN

I do indeed prefer the use of unpack over my solution as it is native perl but I'm not comfortable with using a fixed bit pattern as it may not always be portable. Does seem to work pretty well though.

The code andreas1234567 provided illustrates the importance of knowing which library is being called when checking the return of a function for infinity.

In my own defense andreas1234567 I wasn't advocating the use of Math::BigFloat per se but only trying to show the usefulness of calling the interpreter to get the value for Infinity. I guess I failed in that regard but assisted in uncovering a higher principal.

For your information andreas1234567:

Perl 5.008008, /usr/bin/perl, archname=i386-freebsd-64int, byteorder=1 +2345678 le:inf le:-inf le:nan mbf:inf mbf:-inf mbf:NaN


s//----->\t/;$~="JAPH";s//\r<$~~/;{s|~$~-|-~$~|||s |-$~~|$~~-|||s,<$~~,<~$~,,s,~$~>,$~~>,, $|=1,select$,,$,,$,,1e-1;print;redo}

In reply to Re^2: Infinity and platforms by starbolin
in thread Infinity and platforms by andreas1234567

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.