<?php

/**
 * F
 */
class F
{
    /**
     * 自由度1
     *
     * @var float
     * @access public
     */
    public $d1;

    /**
     * 自由度2
     *
     * @var float
     * @access public
     */
    public $d2;

    public $service;

    public $path;

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

    public function pdf($x)
    {
        $path   = $this->path;
        $result = exec("$path/{$this->service} -exec -method=F -d1={$this->d1} -d2={$this->d2} -f=$x -m=pdf");
        return is_numeric($result) ? $result : (float)$result;
    }

    public function cdf($x)
    {
        $path   = $this->path;
        $result = exec("$path/{$this->service} -exec -method=F -d1={$this->d1} -d2={$this->d2} -f=$x -m=cdf");
        return is_numeric($result) ? $result : (float)$result;
    }

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