Skip to content

Add Bits(double) extension for fractional bit values - #1953

Open
Wallor1 wants to merge 1 commit into
Humanizr:mainfrom
Wallor1:feature/bits-double
Open

Wallor1 wants to merge 1 commit into
Humanizr:mainfrom
Wallor1:feature/bits-double

Conversation

@Wallor1

@Wallor1 Wallor1 commented Aug 6, 2026

Copy link
Copy Markdown

Summary

Adds a Bits(double) overload to ByteSizeExtensions so that a byte size can be created from a fractional number of bits, mirroring the existing Bytes(double) overload.

Motivation

Bytes(...) accepts double, but the symmetric Bits(...) accepted only integral types. This is an API inconsistency: with Bytes(double) you can build a size from fractional bytes (e.g. \2.5.Bytes()), but the same was not possible for bits.

Implementation

\\csharp
public static ByteSize Bits(this double input) =>
ByteSize.FromBytes(input / ByteSize.BitsInByte);
\\

The conversion goes through \FromBytes\ (not \FromBits(long)) to preserve the fractional part.

Tests

Added \DoubleBits\ test verifying \2.5.Bits().Bytes == 0.3125. All 103 tests in \ByteSizeExtensionsTests\ pass.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: cd4893f4-d839-440a-af00-8146cb51f1a0

📥 Commits

Reviewing files that changed from the base of the PR and between ffc2b77 and 280d845.

📒 Files selected for processing (2)
  • src/Humanizer/Bytes/ByteSizeExtensions.cs
  • tests/Humanizer.Tests/Bytes/ByteSizeExtensionsTests.cs

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added support for converting decimal bit values into byte-size values.
    • Fractional inputs are supported for more precise conversions.
  • Tests

    • Added coverage validating conversion of fractional bits to bytes.

Walkthrough

Adds a public Bits(this double) extension that converts bits to ByteSize. Adds a test for fractional double input.

Changes

ByteSize conversion

Layer / File(s) Summary
Double Bits conversion
src/Humanizer/Bytes/ByteSizeExtensions.cs, tests/Humanizer.Tests/Bytes/ByteSizeExtensionsTests.cs
Adds the Bits(this double) extension. It divides bits by ByteSize.BitsInByte before creating a ByteSize. The test verifies that 2.5 bits converts to 0.3125 bytes.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Suggested labels: enhancement

Suggested reviewers: clairernovotny

Poem

A rabbit counts bits in a neat little row,
Divides them by eight, and watches bytes grow.
Two point five bits hop into the chute,
And out comes a byte-sized fraction to boot.
“Accurate,” I whisper, with ears held high.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the added Bits(double) extension for fractional bit values.
Description check ✅ Passed The description directly explains the API change, motivation, implementation, and test coverage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Warning

⚠️ This pull request shows signs of AI-generated slop (redundant_comments). It has been flagged by CodeRabbit slop detection and should be reviewed carefully.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 280d845a01

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +54 to +55
public static ByteSize Bits(this double input) =>
ByteSize.FromBytes(input / ByteSize.BitsInByte);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Regenerate the current API reference

This adds a public ByteSizeExtensions.Bits(this double) overload, but the checked-in current API reference was not updated; website/docs/api/Humanizer.ByteSizeExtensions.md still lists only the existing bit overloads for byte/int/long/sbyte/short/uint/ushort at lines 16-22, so the generated docs and snapshot.ps1 -Version current -Check will be stale for this new API. Please regenerate and commit the current API reference with the new overload.

AGENTS.md reference: AGENTS.md:L50-L52

Useful? React with 👍 / 👎.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant