Skip to content

Commit

Permalink
fix: correctly handle signed zeroes in math/base/special/atanf
Browse files Browse the repository at this point in the history
PR-URL: 	#2115
Ref: #2113
Reviewed-by: Athan Reines <[email protected]>
  • Loading branch information
gunjjoshi authored Apr 3, 2024
1 parent 17e2839 commit 4c5cc36
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/node_modules/@stdlib/math/base/special/atanf/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ function atanf( x ) {
var y;
var z;

if ( isnanf( x ) ) {
return NaN;
if ( isnanf( x ) || x === 0.0 ) {
return x;
}
x = float64ToFloat32( x );
if ( x < 0.0 ) {
Expand Down
4 changes: 2 additions & 2 deletions lib/node_modules/@stdlib/math/base/special/atanf/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ float stdlib_base_atanf( const float x ) {
float y;
float z;

if ( stdlib_base_is_nanf( x ) ) {
return 0.0f / 0.0f; // NaN
if ( stdlib_base_is_nanf( x ) || x == 0.0f ) {
return x;
}
ax = x;
if ( x < 0.0f ) {
Expand Down
20 changes: 20 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/atanf/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var abs = require( '@stdlib/math/base/special/abs' );
var EPS = require( '@stdlib/constants/float32/eps' );
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
var isNegativeZerof = require( '@stdlib/math/base/assert/is-negative-zerof' );
var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' );
var atanf = require( './../lib' );


Expand Down Expand Up @@ -396,3 +398,21 @@ tape( 'the function returns `NaN` if provided `NaN`', function test( t ) {
t.equal( isnanf( v ), true, 'returns NaN' );
t.end();
});

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

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

v = atanf( 0.0 );
t.equal( isPositiveZerof( v ), true, 'returns +0' );

v = atanf( +0.0 );
t.equal( isPositiveZerof( v ), true, 'returns +0' );

t.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var abs = require( '@stdlib/math/base/special/abs' );
var EPS = require( '@stdlib/constants/float32/eps' );
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
var isNegativeZerof = require( '@stdlib/math/base/assert/is-negative-zerof' );
var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' );
var tryRequire = require( '@stdlib/utils/try-require' );


Expand Down Expand Up @@ -405,3 +407,21 @@ tape( 'the function returns `NaN` if provided `NaN`', opts, function test( t ) {
t.equal( isnanf( v ), true, 'returns NaN' );
t.end();
});

tape( 'the function returns `-0` if provided `-0`', opts, function test( t ) {
var v = atanf( -0.0 );
t.equal( isNegativeZerof( v ), true, 'returns -0' );
t.end();
});

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

v = atanf( 0.0 );
t.equal( isPositiveZerof( v ), true, 'returns +0' );

v = atanf( +0.0 );
t.equal( isPositiveZerof( v ), true, 'returns +0' );

t.end();
});

1 comment on commit 4c5cc36

@stdlib-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage Report

Package Statements Branches Functions Lines
math/base/special/atanf $\color{green}284/284$
$\color{green}+100.00\%$
$\color{green}21/21$
$\color{green}+100.00\%$
$\color{green}3/3$
$\color{green}+100.00\%$
$\color{green}284/284$
$\color{green}+100.00\%$

The above coverage report was generated for the changes in this push.

Please sign in to comment.