A variant of the gamma function. - Java java.lang

Java examples for java.lang:Math Function

Description

A variant of the gamma function.

Demo Code

/*/*from   w ww.ja v a  2 s  .c  om*/
 * Copyright (c) 2006-2011 Karsten Schmidt
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * http://creativecommons.org/licenses/LGPL/2.1/
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */
//package com.java2s;

public class Main {
    /**
     * A variant of the gamma function.
     * @param a the number to apply gain to
     * @param b the gain parameter. 0.5 means no change, smaller values reduce gain, larger values increase gain.
     * @return the output value
     */
    public static float gain(float a, float b) {
        /*
         float p = (float)Math.log(1.0 - b) / (float)Math.log(0.5);

         if (a < .001)
         return 0.0f;
         else if (a > .999)
         return 1.0f;
         if (a < 0.5)
         return (float)Math.pow(2 * a, p) / 2;
         else
         return 1.0f - (float)Math.pow(2 * (1. - a), p) / 2;
         */
        float c = (1.0f / b - 2.0f) * (1.0f - 2.0f * a);
        if (a < 0.5)
            return a / (c + 1.0f);
        else
            return (c - a) / (c - 1.0f);
    }
}

Related Tutorials