Changeset 2315 for branches/0.6-stable


Ignore:
Timestamp:
Aug 20, 2010, 5:51:00 AM (13 years ago)
Author:
Peter
Message:

prefer casting to double first and then multiply rather than the opposite. fixes #638

Location:
branches/0.6-stable
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/0.6-stable/test/fisher_test.cc

    r2314 r2315  
    123123void test_large_numbers(test::Suite& suite)
    124124{
     125  // skip test if unsigned int is 16 bit
     126  if (UINT_MAX == ( 1 << 16))
     127    return;
     128
    125129  statistics::Fisher f;
    126130  double oddsratio = f.oddsratio(1166,63326825-1166,1095,66074759-1095);
     
    130134    suite.xadd(false);
    131135  }
    132 
     136  f.p_value();
     137  f.p_value_one_sided();
    133138}
  • branches/0.6-stable/yat/statistics/Fisher.cc

    r2119 r2315  
    3030
    3131#include <algorithm>
     32#include <cassert>
    3233
    3334namespace theplu {
     
    6465  void Fisher::expected(double& a, double& b, double& c, double& d) const
    6566  {
    66     double N = a_+b_+c_+d_;
     67    // use floting point arithmetic to avoid overflow
     68    double N = static_cast<double>(a_) + static_cast<double>(b_)
     69      + static_cast<double>(c_) + static_cast<double>(d_);
    6770    a =((a_+b_)*(a_+c_)) / N;
    6871    b =((a_+b_)*(b_+d_)) / N;
     
    98101    d_ = d;
    99102
    100     oddsratio_=static_cast<double>(a*d)/static_cast<double>(b*c);
     103    oddsratio_= (static_cast<double>(a) / static_cast<double>(b) *
     104                 static_cast<double>(d) / static_cast<double>(c) );
    101105    return oddsratio_;
    102106  }
     
    118122      return p_value_approximative()/2.0;
    119123    }
     124    // check for overflow
     125    assert(c_ <= c_+d_ && d_ <= c_+d_);
     126    assert(a_ <= a_+b_ && b_ <= a_+b_);
     127    assert(a_ <= a_+c_ && c_ <= a_+c_);
     128
    120129    return statistics::cdf_hypergeometric_P(c_, c_+d_, a_+b_, a_+c_);
    121130  }
     
    147156  }
    148157
    149 
    150158}}} // of namespace statistics, yat, and theplu
Note: See TracChangeset for help on using the changeset viewer.