Boost C++ Libraries: Ticket #7177: Students t returns rubbihs values for undefined input instead of throw https://svn.boost.org/trac10/ticket/7177 <p> Reported by Thomas Mang </p> <p> According to the documentation, in boost 1-50 non-member functions of moments (e.g. mean, variance) which are not defined for a given distribution shall issue compile-time errors, or throw a domain_error at runtime otherwise. For the Cauchy Distribution, that's what it does. For the t-distribution, that's not what it does - the non-member functions happily return some complete rubbish values for mean and variance (and hence I'd also suppose standard deviation). For kurtosis and skewness it seems to work correctly but are subject to mathematical definitions. I have not tested other non-member functions. </p> <p> typedef boost::math::students_t_distribution&lt;double&gt; t_distr; </p> <p> <em> this is ok std::cout &lt;&lt; "mean(t(2)): " &lt;&lt; boost::math::mean( t_distr(2) ) &lt;&lt; std::endl; </em></p> <p> <em> this is NOT ok - first moment not defined for given distribution std::cout &lt;&lt; "mean(t(1)): " &lt;&lt; boost::math::mean( t_distr(1) ) &lt;&lt; std::endl; </em></p> <p> <em> this is ok std::cout &lt;&lt; "var(t(3)): " &lt;&lt; boost::math::variance( t_distr(3) ) &lt;&lt; std::endl; </em></p> <p> <em> this might be ok or not </em> depending on point of view, either Inf or undefined std::cout &lt;&lt; "var(t(2)): " &lt;&lt; boost::math::variance( t_distr(2) ) &lt;&lt; std::endl; </p> <p> <em> this is NOT ok - second moment not defined for the given distribution std::cout &lt;&lt; "var(t(1)): " &lt;&lt; boost::math::variance( t_distr(1) ) &lt;&lt; std::endl; </em></p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7177 Trac 1.4.3 Paul A. Bristow Thu, 02 Aug 2012 08:59:16 GMT status, version changed; resolution set https://svn.boost.org/trac10/ticket/7177#comment:1 https://svn.boost.org/trac10/ticket/7177#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>version</strong> <span class="trac-field-old">Boost 1.50.0</span> → <span class="trac-field-new">Boost Development Trunk</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> After much discussion, we decided to make all moments when df =&lt; moment index k throw domain error (and return NaN is the throw is ignored by a policy). </p> <p> Sources are unclear on this, Wikipedia claiming variance should be ∞ for 1 &lt; \nu ≤ 2, etc. but this probably only applies if df is integral and this package allows real values. </p> <p> And no practical use of having a return of infinity rather than NaN was proposed. </p> <p> So, in the absence of a good case, we have Kept It Simple Sirs and returned quiet_NaN. </p> Ticket