1.0.0 • Published 8 years ago

math-float32-nextafter v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

nextafterf

NPM version Build Status Coverage Status Dependencies

Returns the next representable single-precision floating-point number after x toward y.

Installation

$ npm install math-float32-nextafter

Usage

var nextafterf = require( 'math-float32-nextafter' );

nextafterf( x, y )

Returns the next representable single-precision floating-point number after x toward y.

var z = nextafterf( 1, 100 )
// returns 1.0000001192092896

z = nextafterf( 1, 0 );
// returns 0.9999999403953552

z = nextafterf( -8388608, -1e38 );
// returns -8388609

If x equals y, the function returns y, ensuring consistent behavior around zero.

var z = nextafterf( +0.0, -0.0 );
// returns -0.0

z = nextafterf( -0.0, +0.0 );
// returns +0.0

If either x or y is NaN, the function returns NaN.

var z = nextafterf( NaN, 5.0 );
// returns NaN

z = nextafterf( 5.0, NaN );
// returns NaN

z = nextafterf( NaN, NaN );
// returns NaN

Examples

var PINF = require( 'const-pinf-float32' );
var NINF = require( 'const-ninf-float32' );
var toFloat32 = require( 'float64-to-float32' );
var nextafterf = require( 'math-float32-nextafter' );

var x;
var y;
var z;
var i;

for ( i = 0; i < 100; i++ ) {
	x = Math.random()*1e6 - 5e5;
	x = toFloat32( x );
	if ( Math.random() < 0.5 ) {
		y = NINF;
	} else {
		y = PINF;
	}
	z = nextafterf( x, y );
	console.log( 'x = %d, y = %d. nextafterf(x,y) => %d', x, y, z );
}

To run the example code from the top-level application directory,

$ node ./examples/index.js

Tests

Unit

This repository uses tape for unit tests. To run the tests, execute the following command in the top-level application directory:

$ make test

All new feature development should have corresponding unit tests to validate correct functionality.

Test Coverage

This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:

$ make test-cov

Istanbul creates a ./reports/coverage directory. To access an HTML version of the report,

$ make view-cov

Browser Support

This repository uses Testling for browser testing. To run the tests in a (headless) local web browser, execute the following command in the top-level application directory:

$ make test-browsers

To view the tests in a local web browser,

$ make view-browser-tests

License

MIT license.

Copyright

Copyright © 2016. The Compute.io Authors.