Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
More robust finite/isfinite checking in bad.pd ripped from pdlcore.c.PL
This might be overkill, but seems to be a more robust way of checking
the availability of various finite/isfinite options.
  • Loading branch information
d-lamb committed May 16, 2016
1 parent 6ba3efe commit 689ab29
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion Basic/Bad/bad.pd
Expand Up @@ -31,6 +31,7 @@ use strict;

# check for bad value support
use PDL::Config;
use PDL::Core::Dev;
my $bvalflag = $PDL::Config{WITH_BADVAL} || 0;
my $usenan = $PDL::Config{BADVAL_USENAN} || 0;
my $bvalPerPdl = $PDL::Config{BADVAL_PER_PDL} || 0;
Expand Down Expand Up @@ -182,10 +183,43 @@ sub PDL::copybad { return $_[0]->copy; } # ignore the mask

# _finite in VC++
if ($^O =~ /MSWin/) {
pp_addhdr('
pp_addhdr('
#define finite _finite
#include <float.h>
');
} else
{ #taken from pdlcore.c.PL. Probably overkill here: could we just do '#define finite isfinite' ?
my $finite_inc;
my $use_isfinite = 0;
foreach my $inc ( qw/ math.h ieeefp.h / )
{
if ( trylink ('', "#include <$inc>", 'isfinite(3.2);', '' ) ) {
$finite_inc = $inc;
$use_isfinite = 1;
last;
}
if ( (!defined($finite_inc)) and trylink ("finite: $inc", "#include <$inc>", 'finite(3.2);','') ) {
$finite_inc = $inc;
}
}

if ( defined $finite_inc ) {
pp_addhdr("
#include <$finite_inc>
#define finite(a) (isfinite(a))
");
} else {
pp_addhdr('
/* Kludgy finite/isfinite because bad.pd was unable to find one in your math library */
#ifndef finite
#ifdef isfinite
#define finite isfinite
#else
#define finite(a) (((a) * 0) == (0))
#endif
#endif
');
}
}

pp_add_exported( '',
Expand Down

0 comments on commit 689ab29

Please sign in to comment.