Skip to content

fix: evaluate large arguments accurately in math/base/special/fresnelf - #16119

Draft
Abhist17 wants to merge 1 commit into
stdlib-js:developfrom
Abhist17:fix/fresnelf-large-arguments
Draft

Abhist17 wants to merge 1 commit into
stdlib-js:developfrom
Abhist17:fix/fresnelf-large-arguments

Conversation

@Abhist17

Copy link
Copy Markdown
Contributor

Description

What is the purpose of this pull request?

This pull request:

It has the same two problems, and the second is worse in single precision:

  1. For x > 36974 it returned exactly 0.5, although the oscillating terms are of size 1/(πx).
  2. sincosf( HALF_PI * x2 ) used the rounded x*x. A float32 x*x near x = 3000 is off by up to 0.5, which is most of a radian of argument.

The fix reduces x² modulo 4 exactly. A Veltkamp split with 4097 = 2^12+1 leaves 12-bit halves, so every partial product is exact in single precision, and each one is reduced with fmodf. The asymptotic branch now runs up to 2^24, where 1/(πx) is below half an ulp of 0.5.

set develop this PR (S / C)
small [1e-4, 9.99] 20 ULPs 3 / 7
medium [10, 100] 160 1
large [100, 36968] 5120 0
huge [4e4, 2^24] 320 1

Related Issues

Does this pull request have any related issues?

None. Follows #16118.

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 single-precision counterpart of stdlib-js#16118. Above `x = 36974` the function
returned exactly `0.5`, and below it `sincosf` was evaluated on the rounded
`x*x`, which in single precision costs most of a radian by `x = 3000`.
Reduce `x^2` modulo 4 exactly with a Veltkamp split (`4097 = 2^12+1`) and
keep the asymptotic branch up to `2^24`, where `1/(πx)` is below half an
ulp of `0.5`.

The C/Cephes fixtures are replaced by the BigFloat Julia runner from

Signed-off-by: Abhist17 <abhistkamle.170903@gmail.com>
stdlib-js#16118, evaluated at single-precision inputs.
@Abhist17
Abhist17 requested a review from a team October 13, 2026 13:58
@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/fresnelf $\\color{red}574/578$
$\\color{green}+99.31\\%$
$\\color{red}28/30$
$\\color{green}+93.33\\%$
$\\color{green}7/7$
$\\color{green}+100.00\\%$
$\\color{red}574/578$
$\\color{green}+99.31\\%$

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

@Abhist17
Abhist17 marked this pull request as draft October 14, 2026 04:17
@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