<?php

/**
 * StudentT
 */
class studentT
{
    /**
     * 自由度
     *
     * @var float
     * @access public
     */
    public $freedom;

    public $service;

    public $path;

    /**
     * 构造方法。
     *
     * The construct function.
     *
     * @access public
     * @return void
     */
    public function __construct($freedom)
    {
        global $config;
        $this->service = $config->gonumService;
        $this->path    = dirname(__DIR__);
        $this->freedom = $freedom;
    }

    public function pdf($x)
    {
        $path   = $this->path;
        $result = exec("$path/{$this->service} -exec -method=studentT -freedom={$this->freedom} -t=$x -m=pdf");
        return is_numeric($result) ? $result : (float)$result;
    }

    public function cdf($x)
    {
        $path   = $this->path;
        $result = exec("$path/{$this->service} -exec -method=studentT -freedom={$this->freedom} -t=$x -m=cdf");
        return is_numeric($result) ? $result : (float)$result; 
    }

    public function inverse($p)
    {
        $path   = $this->path;
        $result = exec("$path/{$this->service} -exec -method=studentT -freedom={$this->freedom} -t=$p -m=inv");
        return is_numeric($result) ? $result : (float)$result;  
    }
}
