-
-
Notifications
You must be signed in to change notification settings - Fork 485
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
feat: add math/base/special/cinvf
#3103
base: develop
Are you sure you want to change the base?
Conversation
tape( 'the function may overflow', function test( t ) {
var v;
v = cinvf( new Complex64( 5.0e-324, 5.0e-324 ) );
t.strictEqual( real( v ), PINF, 'real component is +infinity' );
t.strictEqual( imag( v ), NINF, 'imaginary component is -infinity' );
v = cinvf( new Complex64( -5.0e-324, 5.0e-324 ) );
t.strictEqual( real( v ), NINF, 'real component is -infinity' );
t.strictEqual( imag( v ), NINF, 'imaginary component is -infinity' );
v = cinvf( new Complex64( -5.0e-324, -5.0e-324 ) );
t.strictEqual( real( v ), NINF, 'real component is -infinity' );
t.strictEqual( imag( v ), PINF, 'imaginary component is +infinity' );
v = cinvf( new Complex64( 5.0e-324, -5.0e-324 ) );
t.strictEqual( real( v ), PINF, 'real component is +infinity' );
t.strictEqual( imag( v ), PINF, 'imaginary component is +infinity' );
v = cinvf( new Complex64( 0.0, 5.0e-324 ) );
t.strictEqual( real( v ), 0.0, 'real component is 0' );
t.strictEqual( imag( v ), NINF, 'imaginary component is -infinity' );
v = cinvf( new Complex64( 0.0, -5.0e-324 ) );
t.strictEqual( real( v ), 0.0, 'real component is 0' );
t.strictEqual( imag( v ), PINF, 'imaginary component is +infinity' );
v = cinvf( new Complex64( 5.0e-324, 0.0 ) );
t.strictEqual( real( v ), PINF, 'real component is +infinity' );
t.strictEqual( imag( v ), 0.0, 'imaginary component is 0' );
v = cinvf( new Complex64( -5.0e-324, 0.0 ) );
t.strictEqual( real( v ), NINF, 'real component is -infinity' );
t.strictEqual( imag( v ), 0.0, 'imaginary component is 0' );
t.end();
}); Good Afternoon, @gunjjoshi can you please help me out in adding the overflow testcase in test.js and test.native.js as it is not there in this PR right now, i tried various values for this but the complex number |
@aayush0325 Tried the following test on your branch, and it works: tape( 'the function may produce very large values for very small inputs', function test( t ) {
var v;
v = cinvf( new Complex64( FLOAT32_SMALLEST_NORMAL, FLOAT32_SMALLEST_NORMAL ) );
t.ok( real( v ) > 1e37, 'real component is very large' );
t.ok( imag( v ) < -1e37, 'imaginary component is very large and negative' );
v = cinvf( new Complex64( -FLOAT32_SMALLEST_NORMAL, FLOAT32_SMALLEST_NORMAL ) );
t.ok( real( v ) < -1e37, 'real component is very large and negative' );
t.ok( imag( v ) < -1e37, 'imaginary component is very large and negative' );
v = cinvf( new Complex64( -FLOAT32_SMALLEST_NORMAL, -FLOAT32_SMALLEST_NORMAL ) );
t.ok( real( v ) < -1e37, 'real component is very large and negative' );
t.ok( imag( v ) > 1e37, 'imaginary component is very large and positive' );
v = cinvf( new Complex64( FLOAT32_SMALLEST_NORMAL, -FLOAT32_SMALLEST_NORMAL ) );
t.ok( real( v ) > 1e37, 'real component is very large and positive' );
t.ok( imag( v ) > 1e37, 'imaginary component is very large and positive' );
v = cinvf( new Complex64( 0.0, FLOAT32_SMALLEST_NORMAL ) );
t.strictEqual( real( v ), 0.0, 'real component is 0' );
t.ok( imag( v ) < -1e37, 'imaginary component is very large and negative' );
v = cinvf( new Complex64( 0.0, -FLOAT32_SMALLEST_NORMAL ) );
t.strictEqual( real( v ), 0.0, 'real component is 0' );
t.ok( imag( v ) > 1e37, 'imaginary component is very large and positive' );
v = cinvf( new Complex64( FLOAT32_SMALLEST_NORMAL, 0.0 ) );
t.ok( real( v ) > 1e37, 'real component is very large and positive' );
t.strictEqual( imag( v ), 0.0, 'imaginary component is 0' );
v = cinvf( new Complex64( -FLOAT32_SMALLEST_NORMAL, 0.0 ) );
t.ok( real( v ) < -1e37, 'real component is very large and negative' );
t.strictEqual( imag( v ), 0.0, 'imaginary component is 0' );
t.end();
}); You can try this. I think there might be a loss of precision as we are handling single-precision floating-point numbers and as we are not explicitly returning |
You can declare separate variables for var tiny = -1e37;
var huge = 1e37; and then use them in the tests. |
thanks @gunjjoshi! i'll push these changes soon, anything else to add? i'll make all the changes together then. |
Nothing for now, once you've added these tests in both |
updated the tests, kindly review @gunjjoshi. |
lib/node_modules/@stdlib/math/base/special/cinvf/benchmark/c/Makefile
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/math/base/special/cinvf/benchmark/c/native/Makefile
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/math/base/special/cinvf/docs/types/index.d.ts
Outdated
Show resolved
Hide resolved
t.strictEqual( real( q ), qre[ i ], 'returns expected real component' ); | ||
} else { | ||
delta = absf( real( q ) - qre[ i ] ); | ||
tol = 5 * EPS * absf( qre[ i ] ); |
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 tolerance, and tolerances for the tests below are different from what we have in test.js
. Is there any specific reason for this? Ideally, the tolerances much match.
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.
when i run the tests locally, the tolerance in test.js
was appropriate for all test cases to pass. the c files had some more inaccuracy due to the single-precision nature of the code hence i had to increase the tolerance to pass the tests. i think this is because i used fmaxf
instead of stdlib_base_maxf
. will update the C code and see if i can match both the tolerances.
lib/node_modules/@stdlib/math/base/special/cinvf/test/test.native.js
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/math/base/special/cinvf/test/test.native.js
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/math/base/special/cinvf/test/test.native.js
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/math/base/special/cinvf/test/test.native.js
Outdated
Show resolved
Hide resolved
@gunjjoshi even after using |
@aayush0325 As mentioned above, you should make sure that the fixtures generated fall within the range of single-precision floating-point numbers. |
Resolves a part of #649
Description
This pull request:
Related Issues
This pull request:
Questions
No.
Other
Need help with overflow case.
Checklist
@stdlib-js/reviewers