Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ function atan2( y, x ) {
}
q = atan( y / x );
if ( x < 0.0 ) {
if ( q <= 0.0 ) {
if ( y > 0.0 ) {
return q + PI;
}
return q - PI;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ double stdlib_base_atan2( const double y, const double x ) {
}
q = stdlib_base_atan( y / x );
if ( x < 0.0 ) {
if ( q <= 0.0 ) {
if ( y > 0.0 ) {
return q + STDLIB_CONSTANT_FLOAT64_PI;
}
return q - STDLIB_CONSTANT_FLOAT64_PI;
Expand Down
7 changes: 7 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/atan2/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,10 @@ tape( 'the function evaluates the `atan2` function (when x and y are negative)',
}
t.end();
});

tape( 'the function returns `-PI` if provided a negative `y` and a negative `x` whose ratio underflows', function test( t ) {
t.strictEqual( atan2( -1.0e-300, -1.0e300 ), -PI, 'returns expected value' );
t.strictEqual( atan2( -5.0e-324, -1.0 ), -PI, 'returns expected value' );
t.strictEqual( atan2( 1.0e-300, -1.0e300 ), PI, 'returns expected value' );
t.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,10 @@ tape( 'the function evaluates the `atan2` function (when x and y are negative)',
}
t.end();
});

tape( 'the function returns `-PI` if provided a negative `y` and a negative `x` whose ratio underflows', opts, function test( t ) {
t.strictEqual( atan2( -1.0e-300, -1.0e300 ), -PI, 'returns expected value' );
t.strictEqual( atan2( -5.0e-324, -1.0 ), -PI, 'returns expected value' );
t.strictEqual( atan2( 1.0e-300, -1.0e300 ), PI, 'returns expected value' );
t.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ function atan2f( y, x ) {
}
q = atanf( f32( y / x ) );
if ( x < 0.0 ) {
if ( q <= 0.0 ) {
if ( y > 0.0 ) {
return f32( q + PI );
}
return f32( q - PI );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ float stdlib_base_atan2f( const float y, const float x ) {
}
q = stdlib_base_atanf( y / x );
if ( x < 0.0f ) {
if ( q <= 0.0f ) {
if ( y > 0.0f ) {
return q + STDLIB_CONSTANT_FLOAT32_PI;
}
return q - STDLIB_CONSTANT_FLOAT32_PI;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,10 @@ tape( 'the function evaluates the `atan2f` function (when x and y are negative)'
}
t.end();
});

tape( 'the function returns `-PI` if provided a negative `y` and a negative `x` whose ratio underflows', function test( t ) {
t.strictEqual( atan2f( -1.0e-30, -1.0e30 ), -PI, 'returns expected value' );
t.strictEqual( atan2f( -1.0e-45, -1.0 ), -PI, 'returns expected value' );
t.strictEqual( atan2f( 1.0e-30, -1.0e30 ), PI, 'returns expected value' );
t.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,10 @@ tape( 'the function evaluates the `atan2f` function (when x and y are negative)'
}
t.end();
});

tape( 'the function returns `-PI` if provided a negative `y` and a negative `x` whose ratio underflows', opts, function test( t ) {
t.strictEqual( atan2f( -1.0e-30, -1.0e30 ), -PI, 'returns expected value' );
t.strictEqual( atan2f( -1.0e-45, -1.0 ), -PI, 'returns expected value' );
t.strictEqual( atan2f( 1.0e-30, -1.0e30 ), PI, 'returns expected value' );
t.end();
});
Loading