def canonicalize_half_turns(half_turns: type_alias.TParamVal) -> type_alias.TParamVal:
    """Wraps the input into the range (-1, +1]."""
    if isinstance(half_turns, sympy.Expr):
        if not half_turns.is_constant():
            return half_turns
        half_turns = float(half_turns)
    half_turns %= 2
    if half_turns > 1:
        half_turns -= 2
    return half_turns
Wraps the input into the range (-1, +1].
cirq-core/cirq/value/angle.py