"use strict" ;

/**
 * Bounds a numeric value between 2 numbers.
 * @name clamp
 * @memberof core.maths
 * @function
 * @instance
 * @example
 * var n ;
 *
 * n = clamp(4, 5, 10) ;
 * trace ("n : " + n) ; // 5
 *
 * n = clamp(12, 5, 10) ;
 * trace ("n : " + n) ; // 10
 *
 * n = clamp(6, 5, 10) ;
 * trace ("n : " + n) ; // 5
 *
 * n = clamp(NaN, 5, 10) ;
 * console.log("n : " + n) ; // NaN
 * @param {number} value - The value to clamp.
 * @param {number} min - The min value of the range.
 * @param {number} max - The max value of the range.
 * @return a bound numeric value between 2 numbers.
 */
const clamp = ( value , min , max ) =>
{
    if ( isNaN( value ) )
    {
        return NaN ;
    }
    if ( isNaN( min ) )
    {
        min = value ;
    }
    if ( isNaN( max ) )
    {
        max = value ;
    }
    return Math.max( Math.min( value, max ), min ) ;
}

export default clamp ;