diff --git a/CHANGELOG.md b/CHANGELOG.md index beaf7e299..3d79ccce7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5515,6 +5515,7 @@ A total of 29 people contributed to this release. Thank you to the following con
+- [`6a0cbd9`](https://github.com/stdlib-js/stdlib/commit/6a0cbd9c10f0895d795be449fe1ea2a456f2683a) - **test:** fix tests for native implementation [(#2641)](https://github.com/stdlib-js/stdlib/pull/2641) _(by Gunj Joshi)_ - [`ead1c3b`](https://github.com/stdlib-js/stdlib/commit/ead1c3b780527d8068d9c076e85688be94d53775) - **chore:** update package meta data [(#2640)](https://github.com/stdlib-js/stdlib/pull/2640) _(by stdlib-bot, Athan Reines)_ - [`5df976a`](https://github.com/stdlib-js/stdlib/commit/5df976abacaaf3082890fa852e40edfdf1b79f4b) - **feat:** update namespace TypeScript declarations [(#2637)](https://github.com/stdlib-js/stdlib/pull/2637) _(by stdlib-bot, Philipp Burckhardt)_ - [`854b793`](https://github.com/stdlib-js/stdlib/commit/854b793ecdcc540067d9989f4c14e34fb9b736bb) - **feat:** add C implementation for `math/base/special/ceilsd` _(by Gunj Joshi, Philipp Burckhardt)_ diff --git a/base/special/ceilsd/docs/repl.txt b/base/special/ceilsd/docs/repl.txt index 04e983e11..056cbbc71 100644 --- a/base/special/ceilsd/docs/repl.txt +++ b/base/special/ceilsd/docs/repl.txt @@ -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 ------- diff --git a/base/special/ceilsd/docs/types/test.ts b/base/special/ceilsd/docs/types/test.ts index 7988ebb5c..df1d1b550 100644 --- a/base/special/ceilsd/docs/types/test.ts +++ b/base/special/ceilsd/docs/types/test.ts @@ -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 diff --git a/base/special/ceilsd/src/main.c b/base/special/ceilsd/src/main.c index a4367b405..74065dd37 100644 --- a/base/special/ceilsd/src/main.c +++ b/base/special/ceilsd/src/main.c @@ -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 ) ) { diff --git a/base/special/ceilsd/test/test.native.js b/base/special/ceilsd/test/test.native.js index e9e6cb4e3..324fcc3f2 100644 --- a/base/special/ceilsd/test/test.native.js +++ b/base/special/ceilsd/test/test.native.js @@ -20,6 +20,7 @@ // MODULES // +var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); var PI = require( '@stdlib/constants/float64/pi' ); var PINF = require( '@stdlib/constants/float64/pinf' ); @@ -27,62 +28,70 @@ var NINF = require( '@stdlib/constants/float64/ninf' ); var isnan = require( './../../../../base/assert/is-nan' ); var isNegativeZero = require( './../../../../base/assert/is-negative-zero' ); var isPositiveZero = require( './../../../../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 ); @@ -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 ); @@ -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' ); @@ -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' ); @@ -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;