<commit_before>'use strict';

// MODULES //

var setReadOnly = require( '@stdlib/utils/define-read-only-property' );
var isObject = require( '@stdlib/utils/is-plain-object' );
var isnan = require( '@stdlib/utils/is-nan' );
var randn = require( '@stdlib/math/base/random/randn' );
var validate = require( './validate.js' );
var cauchy0 = require( './_cauchy.js' );


// MAIN //

/**
* Returns a pseudorandom number generator for generating random numbers from a Cauchy distribution.
*
* @param {number} [x0] - location parameter
* @param {PositiveNumber} [gamma] - scale parameter
* @param {Options} [options] - function options
* @param {*} [options.seed] - pseudorandom number generator seed
* @throws {TypeError} `x0` must be a number
* @throws {TypeError} `gamma` argument must be a positive number
* @throws {TypeError} options must be an object
* @returns {Function} pseudorandom number generator
*
* @example
* var cauchy = factory( 0.0, 1.0 );
* var v = cauchy();
* // returns <number>
*
* @example
* var cauchy = factory( -3.0, 0.5, {
*     'seed': 297
* });
* var v = cauchy();
* // returns <number>
*/
function factory() {
	var gamma;
	var opts;
	var rand;
	var prng;
	var err;
	var x0;

	if ( arguments.length === 0 ) {
		rand = randn.factory();
	} else if ( arguments.length === 1 ) {
		opts = arguments[ 0 ];
		if ( !isObject( opts ) ) {
			throw new TypeError( 'invalid input argument. Options argument must be an object. Value: `' + opts + '`.' );
		}
		rand = randn.factory( opts );
	} else {
		x0 = arguments[ 0 ];
		gamma = arguments[ 1 ];
		err = validate( x0, gamma );
		if ( err ) {
			throw err;
		}
		if ( arguments.length > 2 ) {
			opts = arguments[ 2 ];
			if ( !isObject( opts ) ) {
				throw new TypeError( 'invalid input argument. Options argument must be an object. Value: `' + opts + '`.' );
			}
			rand = randn.factory( opts );
		} else {
			rand = randn.factory();
		}
	}
	if ( x0 === void 0 ) {
		prng = cauchy2;
	} else {
		prng = cauchy1;
	}
	/**
	* Returns pseudorandom number drawn from a Cauchy distribution with bound parameters `x0` and `gamma`.
	*
	* @private
	* @returns {number} pseudorandom number
	*
	* @example
	* var v = cauchy1();
	* // returns <number>
	*/
	function cauchy1() {
		return cauchy0( rand, x0, gamma );
	} // end FUNCTION cauchy1()

	/**
	* Returns pseudorandom number drawn from a Cauchy distribution.
	*
	* @private
	* @param {number} x0 - location parameter
	* @param {PositiveNumber} gamma - scale parameter
	* @returns {number} pseudorandom number
	*
	* @example
	* var v = cauchy2( 0.0, 2.0 );
	* // returns <number>
	*
	* @example
	* var r = cauchy2( 1.0, -1.5 );
	* // returns NaN
	*/
	function cauchy2( x0, gamma ) {
		if (
			isnan( x0 ) ||
			isnan( gamma ) ||
			gamma <= 0.0
		) {
			return NaN;
		}
		return cauchy0( rand, x0, gamma );
	} // end FUNCTION cauchy2()

	setReadOnly( prng, 'NAME', 'cauchy' );
	setReadOnly( prng, 'SEED', rand.SEED );
	setReadOnly( prng, 'PRNG', rand );

	return prng;
} // end FUNCTION factory()


// EXPORTS //

module.exports = factory;
<commit_msg>Use base utility to test for NaN<commit_after>'use strict';

// MODULES //

var setReadOnly = require( '@stdlib/utils/define-read-only-property' );
var isObject = require( '@stdlib/utils/is-plain-object' );
var isnan = require( '@stdlib/math/base/utils/is-nan' );
var randn = require( '@stdlib/math/base/random/randn' );
var validate = require( './validate.js' );
var cauchy0 = require( './_cauchy.js' );


// MAIN //

/**
* Returns a pseudorandom number generator for generating random numbers from a Cauchy distribution.
*
* @param {number} [x0] - location parameter
* @param {PositiveNumber} [gamma] - scale parameter
* @param {Options} [options] - function options
* @param {*} [options.seed] - pseudorandom number generator seed
* @throws {TypeError} `x0` must be a number
* @throws {TypeError} `gamma` argument must be a positive number
* @throws {TypeError} options must be an object
* @returns {Function} pseudorandom number generator
*
* @example
* var cauchy = factory( 0.0, 1.0 );
* var v = cauchy();
* // returns <number>
*
* @example
* var cauchy = factory( -3.0, 0.5, {
*     'seed': 297
* });
* var v = cauchy();
* // returns <number>
*/
function factory() {
	var gamma;
	var opts;
	var rand;
	var prng;
	var err;
	var x0;

	if ( arguments.length === 0 ) {
		rand = randn.factory();
	} else if ( arguments.length === 1 ) {
		opts = arguments[ 0 ];
		if ( !isObject( opts ) ) {
			throw new TypeError( 'invalid input argument. Options argument must be an object. Value: `' + opts + '`.' );
		}
		rand = randn.factory( opts );
	} else {
		x0 = arguments[ 0 ];
		gamma = arguments[ 1 ];
		err = validate( x0, gamma );
		if ( err ) {
			throw err;
		}
		if ( arguments.length > 2 ) {
			opts = arguments[ 2 ];
			if ( !isObject( opts ) ) {
				throw new TypeError( 'invalid input argument. Options argument must be an object. Value: `' + opts + '`.' );
			}
			rand = randn.factory( opts );
		} else {
			rand = randn.factory();
		}
	}
	if ( x0 === void 0 ) {
		prng = cauchy2;
	} else {
		prng = cauchy1;
	}
	/**
	* Returns pseudorandom number drawn from a Cauchy distribution with bound parameters `x0` and `gamma`.
	*
	* @private
	* @returns {number} pseudorandom number
	*
	* @example
	* var v = cauchy1();
	* // returns <number>
	*/
	function cauchy1() {
		return cauchy0( rand, x0, gamma );
	} // end FUNCTION cauchy1()

	/**
	* Returns pseudorandom number drawn from a Cauchy distribution.
	*
	* @private
	* @param {number} x0 - location parameter
	* @param {PositiveNumber} gamma - scale parameter
	* @returns {number} pseudorandom number
	*
	* @example
	* var v = cauchy2( 0.0, 2.0 );
	* // returns <number>
	*
	* @example
	* var r = cauchy2( 1.0, -1.5 );
	* // returns NaN
	*/
	function cauchy2( x0, gamma ) {
		if (
			isnan( x0 ) ||
			isnan( gamma ) ||
			gamma <= 0.0
		) {
			return NaN;
		}
		return cauchy0( rand, x0, gamma );
	} // end FUNCTION cauchy2()

	setReadOnly( prng, 'NAME', 'cauchy' );
	setReadOnly( prng, 'SEED', rand.SEED );
	setReadOnly( prng, 'PRNG', rand );

	return prng;
} // end FUNCTION factory()


// EXPORTS //

module.exports = factory;

{'fraction_non_alphanumeric': 0.15942736294127216, 'fraction_numerical': 0.017244184154872295, 'mean_word_length': 3.1014009339559707, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '256761', 'n_tokens_mistral': 2362, 'n_tokens_neox': 2156, 'n_words': 662}