(op: str, left: int | float, right: int | float)
| 148 | |
| 149 | |
| 150 | def constant_fold_binary_float_op(op: str, left: int | float, right: int | float) -> float | None: |
| 151 | assert not (isinstance(left, int) and isinstance(right, int)), (op, left, right) |
| 152 | if op == "+": |
| 153 | return left + right |
| 154 | elif op == "-": |
| 155 | return left - right |
| 156 | elif op == "*": |
| 157 | return left * right |
| 158 | elif op == "/": |
| 159 | if right != 0: |
| 160 | return left / right |
| 161 | elif op == "//": |
| 162 | if right != 0: |
| 163 | return left // right |
| 164 | elif op == "%": |
| 165 | if right != 0: |
| 166 | return left % right |
| 167 | elif op == "**": |
| 168 | if (left < 0 and isinstance(right, int)) or left > 0: |
| 169 | try: |
| 170 | ret = left**right |
| 171 | except OverflowError: |
| 172 | return None |
| 173 | else: |
| 174 | assert isinstance(ret, float), ret |
| 175 | return ret |
| 176 | |
| 177 | return None |
| 178 | |
| 179 | |
| 180 | def constant_fold_unary_op(op: str, value: ConstantValue) -> int | float | None: |
no test coverage detected
searching dependent graphs…