in reply to Re: Infinity and platforms
in thread Infinity and platforms

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}