[Boost-bugs] [Boost C++ Libraries] #10110: boost::random::negative_binomial_distribution unnecessary restriction to IntType for parameter k

Subject: [Boost-bugs] [Boost C++ Libraries] #10110: boost::random::negative_binomial_distribution unnecessary restriction to IntType for parameter k
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-06-10 20:23:13


#10110: boost::random::negative_binomial_distribution unnecessary restriction to
IntType for parameter k
-------------------------------------------------+-------------------------
 Reporter: Maximilian Kleinert | Owner: no-
  <kleinert.max@…> | maintainer
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: random
  Version: Boost 1.55.0 | Severity: Problem
 Keywords: random, negative binomial |
  distribution |
-------------------------------------------------+-------------------------
 Hi.

 In the implementation of boost::random::negative_binomial_distribution
 there is an unnecessary restriction to IntType for parameter k.

 A double parameter k will be casted to integer resulting in a different
 distribution than desired. If one compiles with -Wconversion a warning is
 given:
 warning: conversion to ‘int’ from ‘double’ may alter its value
 [-Wconversion]
 see attached example_file.
 This can lead to unwanted realization of a negative binomial distribution
 for non integer parameters k.

 Further there are no assertion checks on the parameters in instantiating a
 boost::random::negative_binomial_distribution object. These assertions are
 checked during the sampling process via boost::random::gamma_distribution.
 There (and in general for negative binomial distribution) the parameter k
 must be strictly greater than zero and not as mentioned in the
 documentation "Requires: k >=0".

 This can easily be extended by changing IntType to RealType in 5
 occurrences regarding the parameter k.

 Thank you,
 Max

 P.S.: I compiled the example file with:
 g++ -Wconversion -o negbin_test -std=c++11 negbin_test.cpp

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/10110>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:16 UTC