spamassassin-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From par...@apache.org
Subject svn commit: rev 10494 - incubator/spamassassin/trunk/lib/Mail/SpamAssassin
Date Sun, 02 May 2004 20:27:45 GMT
Author: parker
Date: Sun May  2 13:27:44 2004
New Revision: 10494

Modified:
   incubator/spamassassin/trunk/lib/Mail/SpamAssassin/Bayes.pm
Log:
Bug 3344: Avoid calling sqrt on negative number

Modified: incubator/spamassassin/trunk/lib/Mail/SpamAssassin/Bayes.pm
==============================================================================
--- incubator/spamassassin/trunk/lib/Mail/SpamAssassin/Bayes.pm	(original)
+++ incubator/spamassassin/trunk/lib/Mail/SpamAssassin/Bayes.pm	Sun May  2 13:27:44 2004
@@ -1099,9 +1099,11 @@
   my $a = $Nb * ( 1 - $p );
   my $b = $Nb * ( $sx + $nb * ( 1 - $p ) - $p * $s ) - $p * $Na * $nb;
   my $c = $Na * $nb * ( $sx - $p * ( $s + $nb ) );
+  my $discrim = $b * $b - 4 * $a * $c;
+  my $disc_max_0 = $discrim < 0 ? 0 : $discrim;
+  my $dd_exact = ( 1.0 - 1e-6 + ( -$b + sqrt( $disc_max_0 ) ) / ( 2*$a ) ) - $na;
 
-  return int( 1.0 - 1e-6 + ( -$b + sqrt( $b * $b - 4 * $a * $c ) ) / ( 2 * $a ) )
-    - $na;
+  return $dd_exact < 1 ? 1 : int($dd_exact);
 }
 
 

Mime
View raw message