Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix tests for native implementation in math/base/special/ceilsd #2641

Merged
merged 1 commit into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Number of significant figures. Must be greater than 0.

b: integer
Base. Must be greater than 0. Default: 10.
Base. Must be greater than 0.

Returns
-------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,6 @@ import ceilsd = require( './index' );

// The compiler throws an error if the function is provided values other than numbers...
{
ceilsd( true, 3 ); // $ExpectError
ceilsd( false, 2 ); // $ExpectError
ceilsd( '5', 1 ); // $ExpectError
ceilsd( [], 1 ); // $ExpectError
ceilsd( {}, 2 ); // $ExpectError
ceilsd( ( x: number ): number => x, 2 ); // $ExpectError

ceilsd( 9, true ); // $ExpectError
ceilsd( 9, false ); // $ExpectError
ceilsd( 5, '5' ); // $ExpectError
ceilsd( 8, [] ); // $ExpectError
ceilsd( 9, {} ); // $ExpectError
ceilsd( 8, ( x: number ): number => x ); // $ExpectError

ceilsd( true, 3, 2 ); // $ExpectError
ceilsd( false, 2, 2 ); // $ExpectError
ceilsd( '5', 1, 2 ); // $ExpectError
Expand Down
6 changes: 3 additions & 3 deletions lib/node_modules/@stdlib/math/base/special/ceilsd/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ double stdlib_base_ceilsd( const double x, const int32_t n, const int32_t b ) {
} else if ( b == 2 ) {
exp = stdlib_base_float64_exponent( stdlib_base_abs( x ) );
} else {
exp = stdlib_base_ln( stdlib_base_abs( x ) ) / stdlib_base_ln( b );
exp = stdlib_base_ln( stdlib_base_abs( x ) ) / stdlib_base_ln( (double)b );
}
exp = stdlib_base_floor( exp - n + 1.0 );
s = stdlib_base_pow( b, stdlib_base_abs( exp ) );
exp = stdlib_base_floor( exp - (double)n + 1.0 );
s = stdlib_base_pow( (double)b, stdlib_base_abs( exp ) );

// Check for overflow:
if ( stdlib_base_is_infinite( s ) ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,69 +20,78 @@

// MODULES //

var resolve = require( 'path' ).resolve;
var tape = require( 'tape' );
var PI = require( '@stdlib/constants/float64/pi' );
var PINF = require( '@stdlib/constants/float64/pinf' );
var NINF = require( '@stdlib/constants/float64/ninf' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' );
var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
var ceilsd = require( './../lib' );
var tryRequire = require( '@stdlib/utils/try-require' );


// VARIABLES //

var ceilsd = tryRequire( resolve( __dirname, './../lib/native.js' ) );
var opts = {
'skip': ( ceilsd instanceof Error )
};


// TESTS //

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

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

v = ceilsd( NaN, 2, 10 );
t.strictEqual( isnan( v ), true, 'returns NaN' );
t.strictEqual( isnan( v ), true, 'returns expected value' );
t.end();
});

tape( 'the function returns `NaN` if provided `n < 1`', function test( t ) {
tape( 'the function returns `NaN` if provided `n < 1`', opts, function test( t ) {
var v;

v = ceilsd( PI, 0, 10 );
t.strictEqual( isnan( v ), true, 'returns NaN' );
t.strictEqual( isnan( v ), true, 'returns expected value' );

v = ceilsd( PI, -1, 10 );
t.strictEqual( isnan( v ), true, 'returns NaN' );
t.strictEqual( isnan( v ), true, 'returns expected value' );

t.end();
});

tape( 'the function returns `NaN` if provided `b <= 0`', function test( t ) {
tape( 'the function returns `NaN` if provided `b <= 0`', opts, function test( t ) {
var v;

v = ceilsd( PI, 2, 0 );
t.strictEqual( isnan( v ), true, 'returns NaN' );
t.strictEqual( isnan( v ), true, 'returns expected value' );

v = ceilsd( PI, 2, -1 );
t.strictEqual( isnan( v ), true, 'returns NaN' );
t.strictEqual( isnan( v ), true, 'returns expected value' );

t.end();
});

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

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

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

v = ceilsd( -0.0, 1, 10 );
Expand All @@ -94,7 +103,7 @@ tape( 'the function returns `-0` if provided `-0`', function test( t ) {
t.end();
});

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

v = ceilsd( 0.0, 1, 10 );
Expand All @@ -106,7 +115,7 @@ tape( 'the function returns `+0` if provided `+0`', function test( t ) {
t.end();
});

tape( 'the function supports rounding a numeric value with a specified number of significant figures (base 10)', function test( t ) {
tape( 'the function supports rounding a numeric value with a specified number of significant figures (base 10)', opts, function test( t ) {
t.strictEqual( ceilsd( PI, 1, 10 ), 4.0, 'returns expected value' );
t.strictEqual( ceilsd( -PI, 1, 10 ), -3.0, 'returns expected value' );
t.strictEqual( ceilsd( PI, 2, 10 ), 3.2, 'returns expected value' );
Expand All @@ -123,7 +132,7 @@ tape( 'the function supports rounding a numeric value with a specified number of
t.end();
});

tape( 'the function supports rounding a numeric value with a specified number of significant figures (base 2)', function test( t ) {
tape( 'the function supports rounding a numeric value with a specified number of significant figures (base 2)', opts, function test( t ) {
t.strictEqual( ceilsd( 0.0313, 1, 2 ), 0.0625, 'returns expected value' );
t.strictEqual( ceilsd( 0.0313, 2, 2 ), 0.046875, 'returns expected value' );
t.strictEqual( ceilsd( 0.0313, 3, 2 ), 0.0390625, 'returns expected value' );
Expand All @@ -141,13 +150,13 @@ tape( 'the function supports rounding a numeric value with a specified number of
t.end();
});

tape( 'the function supports rounding a numeric value with a specified number of significant figures using an arbitrary base', function test( t ) {
tape( 'the function supports rounding a numeric value with a specified number of significant figures using an arbitrary base', opts, function test( t ) {
t.strictEqual( ceilsd( 0.0313, 1, 16 ), 0.03515625, 'returns expected value' );
t.strictEqual( ceilsd( 0.0313, 5, 16 ), 0.03130000829696655, 'returns expected value' );
t.end();
});

tape( 'if the function encounters overflow, the function returns the input value', function test( t ) {
tape( 'if the function encounters overflow, the function returns the input value', opts, function test( t ) {
var x;
var v;

Expand Down
Loading