-
-
Notifications
You must be signed in to change notification settings - Fork 837
fix: update math/base/special/cotd
to match correct reference implementation
#5813
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,11 +62,15 @@ tape( 'the function computes the cotangent of an angle measured in degrees (nega | |
|
||
for ( i = 0; i < x.length; i++ ) { | ||
y = cotd( x[i] ); | ||
if ( expected[ i ] === null ) { | ||
t.equal( y, PINF, 'x: '+x[i]+'. E: '+expected[i] ); | ||
continue; | ||
} | ||
if ( y === expected[ i ] ) { | ||
t.equal( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] ); | ||
} else { | ||
delta = abs( y - expected[i] ); | ||
tol = 1.4 * EPS * abs( expected[i] ); | ||
tol = 2.0 * EPS * abs( expected[i] ); | ||
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); | ||
} | ||
} | ||
|
@@ -86,31 +90,41 @@ tape( 'the function computes the cotangent of an angle measured in degrees (posi | |
|
||
for ( i = 0; i < x.length; i++ ) { | ||
y = cotd( x[i] ); | ||
if ( expected[ i ] === null ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check is included because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
t.equal( y, PINF, 'x: '+x[i]+'. E: '+expected[i] ); | ||
continue; | ||
} | ||
if ( y === expected[ i ] ) { | ||
t.equal( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] ); | ||
} else { | ||
delta = abs( y - expected[i] ); | ||
tol = 1.4 * EPS * abs( expected[i] ); | ||
tol = 2.0 * EPS * abs( expected[i] ); | ||
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); | ||
} | ||
} | ||
t.end(); | ||
}); | ||
|
||
tape( 'if provided `+infinity`, the function returns `NaN`', function test( t ) { | ||
tape( 'if provided `+Infinity`, the function returns `NaN`', function test( t ) { | ||
var v = cotd( PINF ); | ||
t.equal( isnan( v ), true, 'returns NaN' ); | ||
t.end(); | ||
}); | ||
|
||
tape( 'if provided `-infinity`, the function returns `NaN`', function test( t ) { | ||
tape( 'if provided `-Infinity`, the function returns `NaN`', function test( t ) { | ||
var v = cotd( NINF ); | ||
t.equal( isnan( v ), true, 'returns NaN' ); | ||
t.end(); | ||
}); | ||
|
||
tape( 'if provided `90.0`, the function returns `0.0`', function test( t ) { | ||
var v = cotd( 90.0 ); | ||
t.equal( v, 0.0, 'returns expected value' ); | ||
tape( 'if provided `180.0`, the function returns `-Infinity`', function test( t ) { | ||
var v = cotd( 180.0 ); | ||
t.equal( v, NINF, 'returns expected value' ); | ||
t.end(); | ||
}); | ||
|
||
tape( 'if provided `-180.0`, the function returns `+Infinity`', function test( t ) { | ||
Comment on lines
+120
to
+126
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Over here 😄 |
||
var v = cotd( -180.0 ); | ||
t.equal( v, PINF, 'returns expected value' ); | ||
t.end(); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because
cotd( 180.0 )
andcotd( 0.0 )
produce different results. Therefore,180.0
and-180.0
are tested separately.