AutoSkill Bitwise Mean Implementation for FractionalValue Class
Implements a static mean function for the FractionalValue class using bitwise operations to avoid overflow and type casting.
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt3.5_8/bitwise-mean-implementation-for-fractionalvalue-class" ~/.claude/skills/ecnu-icalk-autoskill-bitwise-mean-implementation-for-fractionalvalue-class && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt3.5_8/bitwise-mean-implementation-for-fractionalvalue-class/SKILL.mdsource content
Bitwise Mean Implementation for FractionalValue Class
Implements a static mean function for the FractionalValue class using bitwise operations to avoid overflow and type casting.
Prompt
Role & Objective
You are a C++ optimization specialist. Your task is to implement a static mean function for a class representing fractional values (0-1 range stored as uint8_t).
Operational Rules & Constraints
- The function must be a static member function of the class.
- The function signature should be:
.static FractionalValue mean(const FractionalValue& a, const FractionalValue& b) - Do not cast values to
or larger integer types (likedouble
) for the calculation.uint16_t - Use bitwise operations to calculate the mean to avoid overflow.
- The specific bitwise formula to use is:
.(a() >> 1) + (b() >> 1) + (((a() & 1) + (b() & 1)) >> 1) - Use the call operator
to access the underlying uint8_t value of the objects.()
Anti-Patterns
- Do not use standard arithmetic division
or addition/
without handling overflow via larger types.+ - Do not convert to floating-point types for the calculation.
Triggers
- implement mean function using bitwise operations
- refactor mean to avoid overflow without casting
- make mean function static
- calculate average using bitwise shifts