<commit_before>'use strict';

// MODULES //

var tape = require( 'tape' );
var NINF = require( '@stdlib/math/constants/float64-ninf' );
var PINF = require( '@stdlib/math/constants/float64-pinf' );
var SMALLEST_SUBNORMAL = require( '@stdlib/math/constants/float64-smallest-subnormal' );
var isnan = require( '@stdlib/math/base/utils/is-nan' );
var isNegativeZero = require( '@stdlib/math/base/utils/is-negative-zero' );
var isPositiveZero = require( '@stdlib/math/base/utils/is-positive-zero' );
var exp2 = require( '@stdlib/math/base/special/exp2' );
var truncate2 = require( './../lib' );


// TESTS //

tape( 'main export is a function', function test( t ) {
	t.ok( true, __filename );
	t.strictEqual( typeof truncate2, 'function', 'main export is a function' );
	t.end();
});

tape( 'the function returns `+0` if provided `+0`', function test( t ) {
	var v;

	v = truncate2( 0.0 );
	t.strictEqual( isPositiveZero( v ), true, 'returns +0' );

	v = truncate2( +0.0 );
	t.strictEqual( isPositiveZero( v ), true, 'returns +0' );

	t.end();
});

tape( 'the function returns `-0` if provided `-0`', function test( t ) {
	var v = truncate2( -0.0 );
	t.strictEqual( isNegativeZero( v ), true, 'returns -0' );
	t.end();
});

tape( 'the function returns `NaN` if provided a `NaN`', function test( t ) {
	var v = truncate2( NaN );
	t.strictEqual( isnan( v ), true, 'returns NaN' );
	t.end();
});

tape( 'the function returns `+infinity` if provided a `+infinity`', function test( t ) {
	var v = truncate2( PINF );
	t.strictEqual( v, PINF, 'returns +infinity' );
	t.end();
});

tape( 'the function returns `-infinity` if provided a `-infinity`', function test( t ) {
	var v = truncate2( NINF );
	t.strictEqual( v, NINF, 'returns -infinity' );
	t.end();
});

tape( 'the function returns the minimum double-precision floating-point value if provided the minimum double-precision floating-point value', function test( t ) {
	var v;

	v = truncate2( SMALLEST_SUBNORMAL );
	t.strictEqual( v, SMALLEST_SUBNORMAL, 'returns smallest subnormal' );

	v = truncate2( -SMALLEST_SUBNORMAL );
	t.strictEqual( v, -SMALLEST_SUBNORMAL, 'returns smallest subnormal' );

	t.end();
});

tape( 'the function supports rounding large values', function test( t ) {
	var x;
	var v;

	x = exp2( 1023 );
	v = truncate2( x + (x/2.0) );
	t.strictEqual( v, x, 'returns expected value' );

	x = exp2( 1023 );
	v = truncate2( x + (x/3.0) );
	t.strictEqual( v, x, 'returns expected value' );

	x = -exp2( 1023 );
	v = truncate2( x + (x/2.0) );
	t.strictEqual( v, x, 'returns expected value' );

	x = -exp2( 1023 );
	v = truncate2( x + (x/3.0) );
	t.strictEqual( v, x, 'returns expected value' );

	t.end();
});

tape( 'the function rounds a numeric value to the nearest multiple of two toward zero', function test( t ) {
	t.strictEqual( truncate2( -4.2 ), -4.0, 'returns expected value' );
	t.strictEqual( truncate2( -4.5 ), -4.0, 'returns expected value' );
	t.strictEqual( truncate2( -4.8 ), -4.0, 'returns expected value' );
	t.strictEqual( truncate2( 4.2 ), 4.0, 'returns expected value' );<commit_msg>Add tests for subnormal numbers<commit_after>'use strict';

// MODULES //

var tape = require( 'tape' );
var NINF = require( '@stdlib/math/constants/float64-ninf' );
var PINF = require( '@stdlib/math/constants/float64-pinf' );
var SMALLEST_SUBNORMAL = require( '@stdlib/math/constants/float64-smallest-subnormal' );
var isnan = require( '@stdlib/math/base/utils/is-nan' );
var isNegativeZero = require( '@stdlib/math/base/utils/is-negative-zero' );
var isPositiveZero = require( '@stdlib/math/base/utils/is-positive-zero' );
var exp2 = require( '@stdlib/math/base/special/exp2' );
var pow = require( '@stdlib/math/base/special/pow' );
var truncate2 = require( './../lib' );


// TESTS //

tape( 'main export is a function', function test( t ) {
	t.ok( true, __filename );
	t.strictEqual( typeof truncate2, 'function', 'main export is a function' );
	t.end();
});

tape( 'the function returns `+0` if provided `+0`', function test( t ) {
	var v;

	v = truncate2( 0.0 );
	t.strictEqual( isPositiveZero( v ), true, 'returns +0' );

	v = truncate2( +0.0 );
	t.strictEqual( isPositiveZero( v ), true, 'returns +0' );

	t.end();
});

tape( 'the function returns `-0` if provided `-0`', function test( t ) {
	var v = truncate2( -0.0 );
	t.strictEqual( isNegativeZero( v ), true, 'returns -0' );
	t.end();
});

tape( 'the function returns `NaN` if provided a `NaN`', function test( t ) {
	var v = truncate2( NaN );
	t.strictEqual( isnan( v ), true, 'returns NaN' );
	t.end();
});

tape( 'the function returns `+infinity` if provided a `+infinity`', function test( t ) {
	var v = truncate2( PINF );
	t.strictEqual( v, PINF, 'returns +infinity' );
	t.end();
});

tape( 'the function returns `-infinity` if provided a `-infinity`', function test( t ) {
	var v = truncate2( NINF );
	t.strictEqual( v, NINF, 'returns -infinity' );
	t.end();
});

tape( 'the function returns the minimum double-precision floating-point value if provided the minimum double-precision floating-point value', function test( t ) {
	var v;

	v = truncate2( SMALLEST_SUBNORMAL );
	t.strictEqual( v, SMALLEST_SUBNORMAL, 'returns smallest subnormal' );

	v = truncate2( -SMALLEST_SUBNORMAL );
	t.strictEqual( v, -SMALLEST_SUBNORMAL, 'returns smallest subnormal' );

	t.end();
});

tape( 'the function supports rounding large values', function test( t ) {
	var x;
	var v;

	x = exp2( 1023 );
	v = truncate2( x + (x/2.0) );
	t.strictEqual( v, x, 'returns expected value' );

	x = exp2( 1023 );
	v = truncate2( x + (x/3.0) );
	t.strictEqual( v, x, 'returns expected value' );

	x = -exp2( 1023 );
	v = truncate2( x + (x/2.0) );
	t.strictEqual( v, x, 'returns expected value' );

	x = -exp2( 1023 );
	v = truncate2( x + (x/3.0) );
	t.strictEqual( v, x, 'returns expected value' );

	t.end();
});

tape( 'the function supports rounding subnormal values', function test( t ) {
	var expected;
	var x;
	var v;

	expected = pow( 2.0, -1045 );

	x = pow( 2.0, -1045 );
	v = truncate2( x + (x/2.0) );
	t.strictEqual( v, expected, 'returns expected value' );

	x = pow( 2.0, -1045 );
	v = truncate2( x + (x/3.0) );
	t.strictEqual( v, expected, 'returns expected value' );

	expected = -pow( 2.0, -1045 );

	x = -pow( 2.0, -1045 );
	v = truncate2( x + (x/2.0) );
	t.strictEqual( v, expected, 'returns expected value' );

	x = -pow( 2.0, -1045 );
	v = truncate2( x + (x/3.0) );
	t.strictEqual( v, expected, 'returns expected value' );

	t.end();
});

tape( 'the function rounds a numeric value to the nearest multiple of two toward zero', function test( t ) {
	t.strictEqual( truncate2( -4.2 ), -4.0, 'returns expected value' );
	t.strictEqual( truncate2( -4.5 ), -4.0, 'returns expected value' );
	t.strictEqual( truncate2( -4.8 ), -4.0, 'returns expected value' );
	t.strictEqual( truncate2( 4.2 ), 4.0, 'returns expected value' );
{'fraction_non_alphanumeric': 0.17840444184687318, 'fraction_numerical': 0.031268264172998245, 'mean_word_length': 3.7633959638135, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5936051', 'n_tokens_mistral': 2691, 'n_tokens_neox': 2559, 'n_words': 761}