mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
In cpython, "1.0 / 0.0" raises ZeroDivisionError
```
>>> 1.0 / 0.0
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ZeroDivisionError: float division by zer
```
but RustPython doesn't
```
>>>>> 1.0 / 0.0
inf
```
This is because they emits different byte codes.
```
$ echo "1.0 / 0.0" > zero-div.py
$ python -m dis zero-div.py
1 0 LOAD_CONST 0 (1.0)
2 LOAD_CONST 1 (0.0)
4 BINARY_TRUE_DIVIDE
6 POP_TOP
8 LOAD_CONST 2 (None)
10 RETURN_VALUE
$ cargo run --example dis zero-div.py
zero-div.py:
0 LoadConst (inf)
1 Pop
2 LoadConst (None)
3 ReturnValue
```
This commit stops optimization for zero division case
to generate same byte codes.