Skip to content

Replace hardcoded bit sizes with named constants in Bit<T> methods#111

Merged
konard merged 6 commits intomainfrom
issue-106-48d2da31
Apr 14, 2026
Merged

Replace hardcoded bit sizes with named constants in Bit<T> methods#111
konard merged 6 commits intomainfrom
issue-106-48d2da31

Conversation

@konard
Copy link
Copy Markdown
Member

@konard konard commented Sep 11, 2025

Summary

Fixes #106 by replacing hardcoded magic numbers representing bit sizes with named constants in both the C# and C++ implementations.

Changes Made

C# (csharp/Platform.Numbers/Bit[T].cs)

  • PartialWrite: replaced 32 + shiftBitsSize + shift and 32 + limitBitsSize + limit
  • PartialRead: replaced 32 + shiftBitsSize + shift and 32 + limitBitsSize + limit
  • BitsSize is already defined as NumericType<T>.BitsSize, making the operations generic for any numeric type

C++ (cpp/Platform.Numbers/Bit.h)

  • PartialWrite: replaced sizeof(T) * 8 + shiftsizeof(T) * CHAR_BIT + shift and similarly for limit
  • PartialRead: same replacements
  • Added #include <climits> for CHAR_BIT

Why This Matters

The hardcoded values (32 in C#, 8 in C++) made the code implicitly assume specific type sizes, defeating the purpose of the generic Bit<T> implementation. Using BitsSize / CHAR_BIT makes the intent explicit and correct for all supported numeric types.

Verification

  • Build: Solution compiles successfully
  • C# Tests: 75 passed (1 pre-existing failure in IsPowerOfTwoTest(0) from main branch, unrelated to this PR)
  • Merged latest from main branch

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #106
@konard konard self-assigned this Sep 11, 2025
konard and others added 2 commits September 11, 2025 12:17
- Replace hardcoded 32 values with BitsSize field in PartialWrite and PartialRead methods
- This makes the code generic and work correctly for different numeric types
- All tests pass after the change

Fixes #106

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] Replace 32 with BitsSize Replace 32 with BitsSize in Bit<T> methods Sep 11, 2025
@konard konard marked this pull request as ready for review September 11, 2025 09:23
@konard
Copy link
Copy Markdown
Member Author

konard commented Apr 14, 2026

Get fresh version from default branch and double check all other similar places.

@konard konard marked this pull request as draft April 14, 2026 13:02
@konard
Copy link
Copy Markdown
Member Author

konard commented Apr 14, 2026

🤖 AI Work Session Started

Starting automated work session at 2026-04-14T13:02:07.959Z

The PR has been converted to draft mode while work is in progress.

This comment marks the beginning of an AI work session. Please wait for the session to finish, and provide your feedback.

konard and others added 2 commits April 14, 2026 13:02
Similarly to the C# fix (replacing 32 with BitsSize), replace the
hardcoded magic number 8 with CHAR_BIT from <climits> in the C++
PartialWrite and PartialRead template functions, making the bit
size calculation explicit and portable.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@konard konard changed the title Replace 32 with BitsSize in Bit<T> methods Replace hardcoded bit sizes with named constants in Bit<T> methods Apr 14, 2026
@konard konard marked this pull request as ready for review April 14, 2026 13:04
@konard
Copy link
Copy Markdown
Member Author

konard commented Apr 14, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $0.458140
  • Calculated by Anthropic: $0.458141
  • Difference: $0.000000 (+0.00%)

📊 Context and tokens usage:

  • Context window: 46.7K / 1M (5%) input tokens, 5.3K / 64K (8%) output tokens

Total: (37.0K + 802.7K cached) input tokens, 5.3K output tokens, $0.458140 cost

🤖 Models used:

  • Tool: Anthropic Claude Code
  • Requested: sonnet
  • Model: Claude Sonnet 4.6 (claude-sonnet-4-6)

📎 Log file uploaded as Gist (699KB)


Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Copy Markdown
Member Author

konard commented Apr 14, 2026

🔄 Auto-restart triggered (iteration 1)

Reason: CI failures detected

Starting new session to address the issues.


Auto-restart-until-mergeable mode is active. Will continue until PR becomes mergeable.

@konard
Copy link
Copy Markdown
Member Author

konard commented Apr 14, 2026

Screenshot 2026-04-14 at 6 36 09 PM

This is Codacy issue.

Remove `#include <climits>` which Cppcheck flagged as "Include file not found"
in Codacy Static Code Analysis. Replace `CHAR_BIT` with
`std::numeric_limits<unsigned char>::digits` from `<limits>` (already included),
which is semantically equivalent and avoids the missing-include warning.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@konard
Copy link
Copy Markdown
Member Author

konard commented Apr 14, 2026

🔄 Auto-restart-until-mergeable Log (iteration 1)

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost: $0.247047

📊 Context and tokens usage:

  • Context window: 30.6K / 1M (3%) input tokens, 3.1K / 64K (5%) output tokens

Total: (18.7K + 433.1K cached) input tokens, 3.1K output tokens, $0.247047 cost

🤖 Models used:

  • Tool: Anthropic Claude Code
  • Requested: sonnet
  • Model: Claude Sonnet 4.6 (claude-sonnet-4-6)

📎 Log file uploaded as Gist (1984KB)


Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Copy Markdown
Member Author

konard commented Apr 14, 2026

✅ Ready to merge

This pull request is now ready to be merged:

  • All CI checks have passed
  • No merge conflicts
  • No pending changes

Monitored by hive-mind with --auto-restart-until-mergeable flag

@konard konard merged commit b28480c into main Apr 14, 2026
2 checks passed
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.

Replace 32 with BitsSize

1 participant