Skip to content

Fix negative exponent for sub Hz frequency value#556

Merged
corecoding merged 1 commit into
corecoding:developfrom
nitin-io:fix-negative-hz-exponent
Jun 11, 2026
Merged

Fix negative exponent for sub Hz frequency value#556
corecoding merged 1 commit into
corecoding:developfrom
nitin-io:fix-negative-hz-exponent

Conversation

@nitin-io

Copy link
Copy Markdown

Summary

When the refresh rate drops below 1 Hz, the exponent calculation can produce -1:

Math.floor(Math.log(value) / Math.log(unit))

Since the frequency unit array starts at Hz and does not contain negative indices, this results in an undefined unit lookup.

This change clamps the exponent to a minimum value of 0:

Math.max(0, Math.floor(Math.log(value) / Math.log(unit)))

This prevents invalid array access while preserving existing behavior for Hz, KHz, MHz, and GHz values.

Testing

  • Verified normal frequency formatting.
  • Verified GHz values are unaffected.
  • Verified values below 1 Hz no longer produce undefined units.

Fix for Issue: #555

@corecoding corecoding merged commit 4bc08f2 into corecoding:develop Jun 11, 2026
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