From b3e29d21e4e0ef8494ba1a38546ac439b11fd7ae Mon Sep 17 00:00:00 2001 From: GUNJ JOSHI Date: Sun, 21 Jul 2024 09:00:29 +0530 Subject: [PATCH] docs: cast to double, test with native implementation --- .../math/base/special/ceilsd/docs/repl.txt | 2 +- .../base/special/ceilsd/docs/types/test.ts | 14 ------ .../math/base/special/ceilsd/src/main.c | 6 +-- .../base/special/ceilsd/test/test.native.js | 45 +++++++++++-------- 4 files changed, 31 insertions(+), 36 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/ceilsd/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/ceilsd/docs/repl.txt index 04e983e112f2..056cbbc7106b 100644 --- a/lib/node_modules/@stdlib/math/base/special/ceilsd/docs/repl.txt +++ b/lib/node_modules/@stdlib/math/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/lib/node_modules/@stdlib/math/base/special/ceilsd/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/special/ceilsd/docs/types/test.ts index 7988ebb5cc3c..df1d1b55028f 100644 --- a/lib/node_modules/@stdlib/math/base/special/ceilsd/docs/types/test.ts +++ b/lib/node_modules/@stdlib/math/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/lib/node_modules/@stdlib/math/base/special/ceilsd/src/main.c b/lib/node_modules/@stdlib/math/base/special/ceilsd/src/main.c index a4367b4050ab..74065dd3715c 100644 --- a/lib/node_modules/@stdlib/math/base/special/ceilsd/src/main.c +++ b/lib/node_modules/@stdlib/math/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/lib/node_modules/@stdlib/math/base/special/ceilsd/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/ceilsd/test/test.native.js index 61c410d0b61e..34a7e1199c55 100644 --- a/lib/node_modules/@stdlib/math/base/special/ceilsd/test/test.native.js +++ b/lib/node_modules/@stdlib/math/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( '@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 ); @@ -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;