Skip to content

fix: avoid cancellation near |x| = 1 in math/base/special/acsc - #16113

Draft
Abhist17 wants to merge 1 commit into
stdlib-js:developfrom
Abhist17:fix/acsc-near-one
Draft

Abhist17 wants to merge 1 commit into
stdlib-js:developfrom
Abhist17:fix/acsc-near-one

Conversation

@Abhist17

Copy link
Copy Markdown
Contributor

Description

What is the purpose of this pull request?

This pull request:

  • evaluates math/base/special/acsc as sign(x) * atan( 1/sqrt((|x|-1)*(|x|+1)) ) for 1 <= |x| <= 2 (JS and C), instead of asin( 1/x ).

The slope of asin is unbounded at one, so near |x| = 1 it amplifies the rounding of 1/x:

var acsc = require( '@stdlib/math/base/special/acsc' );

acsc( 1.000000001 );
// develop: 1.5707516054334927
// this PR: 1.570751605433515 (256-bit BigFloat: 1.570751605433515)

For x >= 1, cot( acsc(x) ) = sqrt(x^2-1), and |x|-1 is exact for 1 <= |x| <= 2. acsc(±1) is still ±π/2. Elsewhere the function is unchanged.

  • regenerates the fixtures in 256-bit BigFloat. They came from Julia's Float64 acsc and were checked with strictEqual, so they pinned asin(1/x) bit for bit. They are now checked at 1 ULP, the same as most math/base/special packages.
  • adds near_positive_one.json and near_negative_one.json, 1000 values each at ±(1 + 10^k) for k in [-15, -1], which pass at 1 ULP.

Related Issues

Does this pull request have any related issues?

None. Same construction as #16110 (asech), #16111 (acoth) and #16112 (asec).

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

test.js and test.native.js pass.

Checklist

Please ensure the following tasks are completed before submitting this pull request.

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of AI assistance?

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

The slope of `asin` is unbounded at one, so `asin( 1/x )` amplifies the
rounding of `1/x`: `acsc( 1.000000001 )` was off by about 100 ULPs. For
`1 <= |x| <= 2`, evaluate `sign(x) * atan( 1/sqrt((|x|-1)*(|x|+1)) )`
instead, where `|x|-1` is exact.

The fixtures were generated with Julia's Float64 `acsc` and checked for
exact equality; they are now evaluated in BigFloat and checked at 1 ULP,
with new sets of values close to 1 and -1.

Signed-off-by: Abhist17 <abhistkamle.170903@gmail.com>
@Abhist17
Abhist17 requested a review from a team October 13, 2026 13:29
@stdlib-bot stdlib-bot added Math Issue or pull request specific to math functionality. Needs Review A pull request which needs code review. labels Oct 13, 2026
@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
math/base/special/acsc $\\color{green}187/187$
$\\color{green}+100.00\\%$
$\\color{green}11/11$
$\\color{green}+100.00\\%$
$\\color{green}2/2$
$\\color{green}+100.00\\%$
$\\color{green}187/187$
$\\color{green}+100.00\\%$

The above coverage report was generated for the changes in this PR.

@Abhist17
Abhist17 marked this pull request as draft October 14, 2026 04:16
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Oct 14, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Math Issue or pull request specific to math functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants