Ticket #289 (new defect)
Opened 12 months ago
Use of undefined operation to create inf & nan
|Reported by:||jstroud@…||Owned by:||xi|
In constructor.py, around line 256, the following lines are used to create an inf and a nan:
inf_value = 1e300 while inf_value != inf_value*inf_value: inf_value *= inf_value nan_value = -inf_value/inf_value # Trying to make a quiet NaN (like C99).
The problem is that this code makes use of undefined operations. Some strict environments trap undefined operations and raise an exception, causing this code to crash the interpreter when such exceptions are not caught.
A defined way to create an inf and nan is simply:
inf_value = float('inf') nan_nan = float('nan')
The latter is preferred because it will not crash the interpreter in strict environments and also its intent is clearer.