Skip to content

Commit 4c5cc36

Browse files
authored
fix: correctly handle signed zeroes in math/base/special/atanf
PR-URL: #2115 Ref: #2113 Reviewed-by: Athan Reines <[email protected]>
1 parent 17e2839 commit 4c5cc36

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

lib/node_modules/@stdlib/math/base/special/atanf/lib/main.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ function atanf( x ) {
8686
var y;
8787
var z;
8888

89-
if ( isnanf( x ) ) {
90-
return NaN;
89+
if ( isnanf( x ) || x === 0.0 ) {
90+
return x;
9191
}
9292
x = float64ToFloat32( x );
9393
if ( x < 0.0 ) {

lib/node_modules/@stdlib/math/base/special/atanf/src/main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ float stdlib_base_atanf( const float x ) {
8888
float y;
8989
float z;
9090

91-
if ( stdlib_base_is_nanf( x ) ) {
92-
return 0.0f / 0.0f; // NaN
91+
if ( stdlib_base_is_nanf( x ) || x == 0.0f ) {
92+
return x;
9393
}
9494
ax = x;
9595
if ( x < 0.0f ) {

lib/node_modules/@stdlib/math/base/special/atanf/test/test.js

+20
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2525
var abs = require( '@stdlib/math/base/special/abs' );
2626
var EPS = require( '@stdlib/constants/float32/eps' );
2727
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
28+
var isNegativeZerof = require( '@stdlib/math/base/assert/is-negative-zerof' );
29+
var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' );
2830
var atanf = require( './../lib' );
2931

3032

@@ -396,3 +398,21 @@ tape( 'the function returns `NaN` if provided `NaN`', function test( t ) {
396398
t.equal( isnanf( v ), true, 'returns NaN' );
397399
t.end();
398400
});
401+
402+
tape( 'the function returns `-0` if provided `-0`', function test( t ) {
403+
var v = atanf( -0.0 );
404+
t.equal( isNegativeZerof( v ), true, 'returns -0' );
405+
t.end();
406+
});
407+
408+
tape( 'the function returns `0` if provided +0', function test( t ) {
409+
var v;
410+
411+
v = atanf( 0.0 );
412+
t.equal( isPositiveZerof( v ), true, 'returns +0' );
413+
414+
v = atanf( +0.0 );
415+
t.equal( isPositiveZerof( v ), true, 'returns +0' );
416+
417+
t.end();
418+
});

lib/node_modules/@stdlib/math/base/special/atanf/test/test.native.js

+20
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2626
var abs = require( '@stdlib/math/base/special/abs' );
2727
var EPS = require( '@stdlib/constants/float32/eps' );
2828
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
29+
var isNegativeZerof = require( '@stdlib/math/base/assert/is-negative-zerof' );
30+
var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' );
2931
var tryRequire = require( '@stdlib/utils/try-require' );
3032

3133

@@ -405,3 +407,21 @@ tape( 'the function returns `NaN` if provided `NaN`', opts, function test( t ) {
405407
t.equal( isnanf( v ), true, 'returns NaN' );
406408
t.end();
407409
});
410+
411+
tape( 'the function returns `-0` if provided `-0`', opts, function test( t ) {
412+
var v = atanf( -0.0 );
413+
t.equal( isNegativeZerof( v ), true, 'returns -0' );
414+
t.end();
415+
});
416+
417+
tape( 'the function returns `0` if provided +0', opts, function test( t ) {
418+
var v;
419+
420+
v = atanf( 0.0 );
421+
t.equal( isPositiveZerof( v ), true, 'returns +0' );
422+
423+
v = atanf( +0.0 );
424+
t.equal( isPositiveZerof( v ), true, 'returns +0' );
425+
426+
t.end();
427+
});

0 commit comments

Comments
 (0)