in reply to Infinity and platforms

Checking the return values against every possible permutation is not the way to write portable code. The proper procedure is to compare the return value against the system's own definition of Infinity. In C we'd compare the return value against the appropriate constant in float.h. Under ISO C99 we call isint() to do the check transparently. Perl being an interpreter we can ask Perl what it thinks the value is:

#!/usr/bin/perl -w use Math::BigFloat; my $inf = Math::BigFloat->binf(); # $inf contains: "inf" print $inf,"\n";

Though if you use any of the Math modules in the core distribution you can import transparent checks for infinity and if you divide by zero in vanilla perl you get an exception. I guess I'm not sure what problem you are trying to solve.

UPDATE: I said "they contain transparent". Changed it to "you can import"


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

Replies are listed 'Best First'.
Re^2: Infinity and platforms
by starbolin (Hermit) on Jan 25, 2008 at 18:21 UTC

    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:


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