time-to-botec/js/node_modules/@stdlib/math/base/assert/is-probability/README.md
NunoSempere b6addc7f05 feat: add the node modules
Necessary in order to clearly see the squiggle hotwiring.
2022-12-03 12:44:49 +00:00

1.5 KiB

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' );
}