--- math.pd_orig	2012-06-27 22:05:26 +1000
+++ math.pd	2012-06-27 20:28:32 +1000
@@ -1,5 +1,6 @@
 
 use strict;
+use Config;
 
 pp_addpm({At=>'Top'},<<'EOD');
 =head1 NAME
@@ -103,7 +104,7 @@
 of the function required.
 ');
 
-if ($^O !~ /win32/i) {  # doesn't seem to be in the MS VC lib
+if ($^O !~ /win32/i || $Config{cc} =~ /\bgcc/i) {  # doesn't seem to be in the MS VC lib
 doco( 'lgamma' ,<<'EOD');
 =for ref
 
@@ -294,6 +295,24 @@
 	   );
 } # if: os !~ win32
 
+elsif ($Config{cc} =~ /\bgcc/i) {
+    pp_def("lgamma",
+	   HandleBad => 1,
+	   Pars => 'a(); [o]b(); int[o]s()',
+	   Doc => $doco{"lgamma"},
+	   Code =>
+	   '$b() = lgamma($a());
+	    $s() = tgamma($a()) < 0 ? -1 : 1;',     # what happens to signgam if $a() is bad?
+	   BadCode => 
+	   'if ( $ISBAD(a()) ) {
+               $SETBAD(b()); $SETBAD(s());
+            } else {
+               $b() = lgamma($a());
+               $s() = tgamma($a()) < 0 ? -1 : 1;
+            }',
+	   );
+} # elsif: cc =~ /\bgcc/i
+
 pp_def(
        'badmask',
        Pars => 'a(); b(); [o]c();',
