Skip to content

BUG: amos/amos.h: fix loop upper bound in buni - #93

Merged
fbourgey merged 2 commits into
scipy:mainfrom
JaRoSchm:amos_buni_fix
Jun 20, 2026
Merged

BUG: amos/amos.h: fix loop upper bound in buni#93
fbourgey merged 2 commits into
scipy:mainfrom
JaRoSchm:amos_buni_fix

Conversation

@JaRoSchm

@JaRoSchm JaRoSchm commented Feb 3, 2026

Copy link
Copy Markdown
Contributor

Hi, I detected this error in the same way as in #92. This time I used z = 90.0 - 3.0j and n = 30 in https://github.com/JaRoSchm/pyamos/blob/main/compare_xsf_zbessel.py for finding the bug. This was simply incorrectly translated from FORTRAN, see https://github.com/scipy/scipy/blob/4edfcaa3ce8a387450b6efce968572def71be089/scipy/special/amos/zbuni.f#L114, where only the lower bound has been shifted by one but not the upper bound. As k is reduced by one for each loop, it will become -1 during the last iteration, such that y as accessed at -1. Regarding testing the same question/comment from #92 applies.

@JaRoSchm

JaRoSchm commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

I checked that CI fails if the fix is reverted, see ca1dbe8.

Fix the upper bound of the loop in buni, which was incorrectly
translated from FORTRAN. This allowed to access the result array out of
its bounds.
@fbourgey
fbourgey merged commit e9dcd1e into scipy:main Jun 20, 2026
8 checks passed
@fbourgey

Copy link
Copy Markdown
Member

Thanks @JaRoSchm!

@JaRoSchm
JaRoSchm deleted the amos_buni_fix branch June 22, 2026 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants