Skip to content

Speed up hts_parse_decimal() handling of oversized exponents#2045

Merged
whitwham merged 1 commit into
samtools:developfrom
daviesrob:exponent-control
Jul 2, 2026
Merged

Speed up hts_parse_decimal() handling of oversized exponents#2045
whitwham merged 1 commit into
samtools:developfrom
daviesrob:exponent-control

Conversation

@daviesrob

Copy link
Copy Markdown
Member

The loop to apply exponent values could be made to run for a very long time (although not forever) if the exponent value in the number passed to the function was very large. As in both the +ve and -ve exponent cases this will eventually result in n becoming zero (the former through overflow), it's possible to short-cut the rest of the loop as the final value will no longer change.

Note that this does not try to add overflow detection, which would require more extensive changes and is left to future work.

The loop to apply exponent values could be made to run for a
very long time (although not forever) if the exponent value
in the number passed to the function was very large.  As in
both the +ve and -ve exponent cases this will eventually
result in `n` becoming zero, it's possible to short-cut the
rest of the loop as the final value will no longer change.
(While the -ve case is obvious, the +ve one is a bit more
complicated due to wrap-around.  However, as each
multiplication by 10 adds a factor of 2 (as 10 = 5 + 2),
after at most 64 enough 2's will have accumulated in the
product to make it divide exactly into 2^64 and the result
will be zero.)

Note that this does not try to add overflow detection, which
would require more extensive changes and is left to future
work.

Signed-off-by: Rob Davies <rmd+git@sanger.ac.uk>
@whitwham whitwham merged commit 385f22c into samtools:develop Jul 2, 2026
9 checks passed
@daviesrob daviesrob deleted the exponent-control branch July 2, 2026 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants