|
||
---|---|---|
.. | ||
docs | ||
lib | ||
package.json | ||
README.md |
isProbability
Test if a numeric value is a probability.
Usage
var isProbability = require( '@stdlib/math/base/assert/is-probability' );
isProbability( x )
Tests if a numeric
value is a probability.
var bool = isProbability( 0.5 );
// returns true
bool = isProbability( 3.14 );
// returns false
bool = isProbability( NaN );
// returns false
Examples
var randu = require( '@stdlib/random/base/randu' );
var isProbability = require( '@stdlib/math/base/assert/is-probability' );
var bool;
var x;
var i;
for ( i = 0; i < 100; i++ ) {
x = ( randu()*2.0 ) - 1.0;
bool = isProbability( x );
console.log( '%d is %s', x, ( bool ) ? 'a probability' : 'not a probability' );
}