Skip to content

feat: add math/base/special/gammasgnf #3365

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

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add math/base/special/gammasgnf
---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
  - task: run_javascript_examples
    status: na
  - task: run_c_examples
    status: na
  - task: run_cpp_examples
    status: na
  - task: run_javascript_readme_examples
    status: na
  - task: run_c_benchmarks
    status: passed
  - task: run_cpp_benchmarks
    status: na
  - task: run_fortran_benchmarks
    status: na
  - task: run_javascript_benchmarks
    status: passed
  - task: run_julia_benchmarks
    status: na
  - task: run_python_benchmarks
    status: na
  - task: run_r_benchmarks
    status: na
  - task: run_javascript_tests
    status: passed
---
  • Loading branch information
vivekmaurya001 committed Jan 18, 2025
commit cb42022bf80d0b8f570ccbc6fc2987f912c3c0e7
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,37 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var Float64Array = require( '@stdlib/array/float64' );
var randu = require( '@stdlib/random/base/randu' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var pkg = require( './../package.json' ).name;
var gammasgnf = require( './../lib' );


// MAIN //

bench( pkg, function benchmark( b ) {
var opts;
var len;
var x;
var y;
var i;

opts = {
'dtype': 'float32'
};

len = 100;
x = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = ( randu()*171.0 ) - 0.0;
}
x = uniform( len, 0, 171, opts );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = gammasgnf( x[ i%len ] );
if ( isnan( y ) ) {
y = gammasgnf( x[ i % len ] );
if ( isnanf( y ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( y ) ) {
if ( isnanf( y ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var Float64Array = require( '@stdlib/array/float64' );
var randu = require( '@stdlib/random/base/randu' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;

Expand All @@ -40,26 +39,28 @@ var opts = {
// MAIN //

bench( pkg+'::native', opts, function benchmark( b ) {
var opts;
var len;
var x;
var y;
var i;

opts = {
'dtype': 'float32'
};

len = 100;
x = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = ( randu() * 171.0 ) - 0.0;
}
x = uniform( len, 0, 171, opts );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = gammasgnf( x[ i%len ] );
if ( isnan( y ) ) {
y = gammasgnf( x[ i % len ] );
if ( isnanf( y ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( y ) ) {
if ( isnanf( y ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,18 @@ static float rand_float( void ) {
*/
static double benchmark( void ) {
double elapsed;
float x;
float x[ 100 ];
float y;
double t;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = ( 171.0 * rand_float() ) - 0.0f;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 171.0 * rand_float() ) - 0.0f;
y = stdlib_base_gammasgnf( x );
y = stdlib_base_gammasgnf( x[ i % 100 ] );
if ( y != y ) {
printf( "should not return NaN\n" );
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

{{alias}}( x )

Computes the sign of the gamma function for
Computes the sign of the gamma function for
a single precision-floating number.

Parameters
Expand All @@ -14,6 +14,7 @@
y: number
Sign of the gamma function.


Examples
--------
> var y = {{alias}}( 1.0 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

// MODULES //

var isnan = require( '@stdlib/math/base/assert/is-nan' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var floorf = require( '@stdlib/math/base/special/floorf' );


Expand Down Expand Up @@ -48,7 +48,7 @@ var floorf = require( '@stdlib/math/base/special/floorf' );
function gammasgnf( x ) {
var fx;

if ( isnan( x ) ) {
if ( isnanf( x ) ) {
return x;
}
if ( x > 0 ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"libpath": [],
"dependencies": [
"@stdlib/math/base/napi/unary",
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/assert/is-nanf",
"@stdlib/math/base/special/floorf"
]
},
Expand All @@ -52,7 +52,7 @@
"libraries": [],
"libpath": [],
"dependencies": [
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/assert/is-nanf",
"@stdlib/math/base/special/floorf"
]
},
Expand All @@ -67,7 +67,7 @@
"libraries": [],
"libpath": [],
"dependencies": [
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/assert/is-nanf",
"@stdlib/math/base/special/floorf"
]
}
Expand Down
18 changes: 9 additions & 9 deletions lib/node_modules/@stdlib/math/base/special/gammasgnf/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
* limitations under the License.
*/

#include "stdlib/math/base/assert/is_nan.h"
#include "stdlib/math/base/special/floorf.h"
#include "stdlib/math/base/special/gammasgnf.h"
#include "stdlib/math/base/assert/is_nanf.h"
#include "stdlib/math/base/special/floorf.h"

/**
* Computes the sign of the gamma function for a single precision-floating point number.
Expand All @@ -27,25 +27,25 @@
* @return sign of the gamma function
*
* @example
* var v = gammasgnf( 1.0 );
* var v = gammasgnf( 1.0f );
* // returns 1.0
*/
float stdlib_base_gammasgnf( const float x ) {
float fx;

if ( stdlib_base_is_nan( x ) ) {
if ( stdlib_base_is_nanf( x ) ) {
return x;
}
if ( x > 0 ) {
return 1.0;
return 1.0f;
}
fx = stdlib_base_floorf( x );
if ( x == fx ) {
return 0.0;
return 0.0f;
}
fx /= 2.0;
fx /= 2.0f;
if ( fx == stdlib_base_floorf( fx ) ) {
return 1.0;
return 1.0f;
}
return -1.0;
return -1.0f;
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
// MODULES //

var tape = require( 'tape' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' );
var gammasgnf = require( './../lib' );


Expand Down Expand Up @@ -125,19 +125,19 @@ tape( 'the function computes the sign of the gamma function for medium negative

tape( 'the function returns `NaN` if provided `NaN`', function test( t ) {
var v = gammasgnf( NaN );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnanf( v ), true, 'returns expected value' );
t.end();
});

tape( 'the function returns `+0` if provided `+0`', function test( t ) {
var v = gammasgnf( +0.0 );
t.equal( isPositiveZero( v ), true, 'returns 0' );
t.equal( isPositiveZerof( v ), true, 'returns expected value' );
t.end();
});

tape( 'the function returns `+0` if provided `-0`', function test( t ) {
var v = gammasgnf( -0.0 );
t.equal( isPositiveZero( v ), true, 'returns 0' );
t.equal( isPositiveZerof( v ), true, 'returns expected value' );
t.end();
});

Expand All @@ -147,7 +147,7 @@ tape( 'the function returns `+0` if provided a negative integer', function test(

for ( i = 0; i >= -100; i-- ) {
v = gammasgnf( i );
t.equal( isPositiveZero( v ), true, 'returns 0' );
t.equal( isPositiveZerof( v ), true, 'returns expected value' );
}
t.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

var resolve = require( 'path' ).resolve;
var tape = require( 'tape' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' );
var tryRequire = require( '@stdlib/utils/try-require' );


Expand Down Expand Up @@ -134,19 +134,19 @@ tape( 'the function computes the sign of the gamma function for medium negative

tape( 'the function returns `NaN` if provided `NaN`', opts, function test( t ) {
var v = gammasgnf( NaN );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnanf( v ), true, 'returns expected value' );
t.end();
});

tape( 'the function returns `+0` if provided `+0`', opts, function test( t ) {
var v = gammasgnf( +0.0 );
t.equal( isPositiveZero( v ), true, 'returns 0' );
t.equal( isPositiveZerof( v ), true, 'returns expected value' );
t.end();
});

tape( 'the function returns `+0` if provided `-0`', opts, function test( t ) {
var v = gammasgnf( -0.0 );
t.equal( isPositiveZero( v ), true, 'returns 0' );
t.equal( isPositiveZerof( v ), true, 'returns expected value' );
t.end();
});

Expand All @@ -156,7 +156,7 @@ tape( 'the function returns `+0` if provided a negative integer', opts, function

for ( i = 0; i >= -100; i-- ) {
v = gammasgnf( i );
t.equal( isPositiveZero( v ), true, 'returns 0' );
t.equal( isPositiveZerof( v ), true, 'returns expected value' );
}
t.end();
});
Loading