math icon indicating copy to clipboard operation
math copied to clipboard

Can't set normal distribution precision to zero

Open kAlvaro opened this issue 8 years ago • 0 comments

<?php
use \Malenki\Math\Stats\NormalDistribution;

require_once __DIR__ . '/vendor/autoload.php';

$normal = new NormalDistribution(1000, 50);
$normal->precision(0);
var_dump($normal->samples(5));

... prints:

array(5) {
  [0]=>
  float(1111.8813325362)
  [1]=>
  float(1040.4406411515)
  [2]=>
  float(973.58864510718)
  [3]=>
  float(969.1747970471)
  [4]=>
  float(1031.454325518)
}

The culprit is this construct, used in several places:

if ($this->int_precision) {
    return round($float_variance, $this->int_precision);
}

kAlvaro avatar Jan 12 '18 09:01 kAlvaro