This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Math-Complex: netbsd-vax: no inf
[perl5.git] / cpan / Math-Complex / lib / Math / Complex.pm
index 19fb164..e77b4d0 100644 (file)
@@ -14,9 +14,28 @@ our $VERSION = 1.59;
 
 use Config;
 
-our($Inf, $ExpInf);
+our ($Inf, $ExpInf);
+our ($vax_float, $has_inf, $has_nan);
+
 BEGIN {
-    my %DBL_MAX =
+    $vax_float = (pack("d",1) =~ /^[\x80\x10]\x40/);
+    $has_inf   = !$vax_float;
+    $has_nan   = !$vax_float;
+
+    unless ($has_inf) {
+      # For example in vax, there is no Inf,
+      # and just mentioning the DBL_MAX (1.70141183460469229e+38)
+      # causes SIGFPE.
+
+      # These are pretty useless without a real infinity,
+      # but setting them makes for less warnings about their
+      # undefined values.
+      $Inf = "Inf";
+      $ExpInf = "Inf";
+      return;
+    }
+
+    my %DBL_MAX =  # These are IEEE 754 maxima.
        (
          4  => '1.70141183460469229e+38',
          8  => '1.7976931348623157e+308',
@@ -26,6 +45,7 @@ BEGIN {
         12 => '1.1897314953572317650857593266280070162E+4932',
         16 => '1.1897314953572317650857593266280070162E+4932',
        );
+
     my $nvsize = $Config{nvsize} ||
                ($Config{uselongdouble} && $Config{longdblsize}) ||
                  $Config{doublesize};
@@ -40,7 +60,7 @@ BEGIN {
     if ($^O eq 'unicosmk') {
        $Inf = $DBL_MAX;
     } else {
-       local $SIG{FPE} = { };
+       local $SIG{FPE} = sub { };
         local $!;
        # We do want an arithmetic overflow, Inf INF inf Infinity.
        for my $t (
@@ -59,12 +79,12 @@ BEGIN {
                $Inf = $i;
                last;
            }
-       }
+          }
        $Inf = $DBL_MAX unless defined $Inf;  # Oh well, close enough.
        die "Math::Complex: Could not get Infinity"
            unless $Inf > $BIGGER_THAN_THIS;
-       $ExpInf = exp(99999);
-    }
+       $ExpInf = eval 'exp(99999)';
+      }
     # print "# On this machine, Inf = '$Inf'\n";
 }
 
@@ -190,9 +210,9 @@ sub _make {
 
     if (defined $p) {
        $p =~ s/^\+//;
-       $p =~ s/^(-?)inf$/"${1}9**9**9"/e;
+       $p =~ s/^(-?)inf$/"${1}9**9**9"/e if $has_inf;
        $q =~ s/^\+//;
-       $q =~ s/^(-?)inf$/"${1}9**9**9"/e;
+       $q =~ s/^(-?)inf$/"${1}9**9**9"/e if $has_inf;
     }
 
     return ($p, $q);
@@ -215,8 +235,8 @@ sub _emake {
     if (defined $p) {
        $p =~ s/^\+//;
        $q =~ s/^\+//;
-       $p =~ s/^(-?)inf$/"${1}9**9**9"/e;
-       $q =~ s/^(-?)inf$/"${1}9**9**9"/e;
+       $p =~ s/^(-?)inf$/"${1}9**9**9"/e if $has_inf;
+       $q =~ s/^(-?)inf$/"${1}9**9**9"/e if $has_inf;
     }
 
     return ($p, $q);