Skip to content

Commit a138af7

Browse files
chore: add test for small negative values
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 050b403 commit a138af7

5 files changed

Lines changed: 51 additions & 12 deletions

File tree

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,20 @@ function digammaf( x ) {
140140
// Argument reduction for tan:
141141
rem = f32( xx - floorf( xx ) );
142142

143-
// Reflect:
144-
xx = f32( 1.0 - xx );
145-
146143
// Check for singularity (negative integer or zero)...
147144
if ( rem === 0.0 ) {
148145
return NaN;
149146
}
150-
if ( rem > 0.5 ) {
151-
rem = f32(rem - 1.0);
147+
if ( rem === 0.5 ) {
148+
tmp = 0.0;
149+
} else {
150+
if ( rem > 0.5 ) {
151+
rem = f32( xx - f32( floorf( xx ) + 1.0 ) );
152+
}
153+
tmp = f32( FLOAT32_PI / tanf( f32( FLOAT32_PI * rem ) ) );
152154
}
153-
tmp = f32( FLOAT32_PI / tanf( f32( FLOAT32_PI * rem ) ) );
155+
// Reflect:
156+
xx = f32( 1.0 - xx );
154157
} else {
155158
tmp = 0.0;
156159
}

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,18 +133,22 @@ float stdlib_base_digammaf( const float x ) {
133133
// Argument reduction for tan:
134134
rem = xx - stdlib_base_floorf( xx );
135135

136-
// Reflect:
137-
xx = 1.0f - xx;
138-
139136
// Check for evaluation at a negative pole:
140137
if ( rem == 0.0f ) {
141138
return 0.0f / 0.0f; // NaN
142139
}
143140

144-
if ( rem > 0.5f ) {
145-
rem -= 1.0f;
141+
if ( rem == 0.5f ) {
142+
tmp = 0.0f;
143+
} else {
144+
if ( rem > 0.5f ) {
145+
rem = xx - ( stdlib_base_floorf( xx ) + 1.0f );
146+
}
147+
tmp = STDLIB_CONSTANT_FLOAT32_PI / stdlib_base_tanf( STDLIB_CONSTANT_FLOAT32_PI * rem );
146148
}
147-
tmp = STDLIB_CONSTANT_FLOAT32_PI / stdlib_base_tanf( STDLIB_CONSTANT_FLOAT32_PI * rem );
149+
150+
// Reflect:
151+
xx = 1.0f - xx;
148152
} else {
149153
tmp = 0.0f;
150154
}

lib/node_modules/@stdlib/math/base/special/digammaf/test/fixtures/julia/runner.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ gen( x, "positive.json" );
7070
x = range( 0.01f0, stop = 0.5f0, length = 200 );
7171
gen( x, "small_positive.json" );
7272

73+
# Generate fixture data for very small negative values:
74+
x = Float32[ -1.0e-10, -1.0e-15, -1.0e-21, -1.0e-25 ];
75+
gen( x, "small_negative.json" );
76+
7377
# Generate fixture data for large positive values:
7478
x = range( 10.0f0, stop = 100.0f0, length = 200 );
7579
gen( x, "large_positive.json" );
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"expected":[1.0e10,1.0e15,1.0e21,1.0e25],"x":[-1.0e-10,-1.0e-15,-1.0e-21,-1.0e-25]}

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ var positive = require( './fixtures/julia/positive.json' );
3434
var smallPositive = require( './fixtures/julia/small_positive.json' );
3535
var largePositive = require( './fixtures/julia/large_positive.json' );
3636
var negative = require( './fixtures/julia/negative.json' );
37+
var smallNegative = require( './fixtures/julia/small_negative.json' );
3738
var nearIntegers = require( './fixtures/julia/near_integers.json' );
3839
var halfIntegers = require( './fixtures/julia/half_integers.json' );
3940
var veryLargePositive = require( './fixtures/julia/very_large_positive.json' );
@@ -174,6 +175,32 @@ tape( 'the function computes the digamma function (large positive values)', func
174175
t.end();
175176
});
176177

178+
tape( 'the function evaluates the digamma function (small negative values)', function test( t ) {
179+
var expected;
180+
var delta;
181+
var tol;
182+
var x;
183+
var y;
184+
var i;
185+
var e;
186+
187+
x = smallNegative.x;
188+
expected = smallNegative.expected;
189+
190+
for ( i = 0; i < x.length; i++ ) {
191+
y = digammaf( x[ i ] );
192+
e = f32( expected[ i ] );
193+
if ( y === e ) {
194+
t.strictEqual( y, e, 'x: ' + x[ i ] + '. E: ' + e );
195+
} else {
196+
delta = absf( y - e );
197+
tol = 150.0 * EPS * absf( e );
198+
t.ok( delta <= tol, 'within tolerance. x: ' + x[ i ] + '. y: ' + y + '. E: ' + e + '. tol: ' + tol + '. Δ: ' + delta + '.' );
199+
}
200+
}
201+
t.end();
202+
});
203+
177204
tape( 'the function computes the digamma function (negative values)', function test( t ) {
178205
var expected;
179206
var delta;

0 commit comments

Comments
 (0)