Re: Infinity and platforms
by GrandFather (Saint) on Jan 18, 2008 at 06:35 UTC
|
The issue is not so much the platform, as the compiler (more particularly, the maths runtime library) that was used to create the Perl interpreter.
Perl is environmentally friendly - it saves trees
| [reply] |
|
|
Is there an overview somewhere of the possible variants of infinity? I want to test functions that are expected to return infinity, independently of architectures, compilers and libraries.
| [reply] |
|
|
SUSv3 says "infinity shall be converted in one of the styles "[-]inf" or "[-]infinity" ; which style is implementation-defined." Unfortunately, MS can't change their broken, made up garbage without breaking their compatibility with folk who have coded to it. I'm rather surprised that Solaris is broken, though.
| [reply] |
|
|
You could check the standards document for C, and cross-check the IEEE arithmetic standard, which I think is IEEE 754.
This could work, especially if you can be reasonably sure that the C-compiler being used is actually standards-compliant, and the standard doesn't say something like "it's up to the compiler builder," which it almost certainly does, so the likely short answer to your question is "No." You may (probably will) have to take this up with members of the numerical analysis community, where they deal with this sort of issue all the time.
emc
Information about American English usage here and here.
Any Northeastern US area jobs? I'm currently unemployed.
| [reply] |
Re: Infinity and platforms
by BrowserUk (Patriarch) on Jan 18, 2008 at 07:24 UTC
|
It would be useful if there was some Config constants setup at build time to map well-known names to the appropriate values, but a quick scan doesn't reveal any.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] |
Re: Infinity and platforms
by rgiskard (Hermit) on Jan 18, 2008 at 13:21 UTC
|
| [reply] [d/l] |
Re: Infinity and platforms
by starbolin (Hermit) on Jan 18, 2008 at 17:56 UTC
|
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}
| [reply] [d/l] |
|
|
| [reply] [d/l] [select] |
Re: Infinity and platforms
by swampyankee (Parson) on Jan 18, 2008 at 19:24 UTC
|
There are also platforms,such as IBM mainframes, which don't define an "infinity." Perl uses the math library of the compiler with which it's built on a given platform. I would suspect that most Linux platforms use the gcc compiler, most commercial Unix-oid systems (such as Solaris or AIX) use their vendor's proprietary compiler, Windows usually uses Microsoft's compiler, etc.
If you're getting "infinities" as the result of a computational process, I would suggest that some rather careful code revisions are required. Numerical programming is rather an arcane speciality, and poking around Netlib, NA-Net, and NCSA may be profitable. Some CS programs are less than thorough in this area, which is something I find quite disturbing.
emc
Information about American English usage here and here.
Any Northeastern US area jobs? I'm currently unemployed.
| [reply] |