Modify

Ticket #289 (new defect)

Opened 12 months ago

Use of undefined operation to create inf & nan

Reported by: jstroud@… Owned by: xi
Priority: normal Component: pyyaml
Severity: normal Keywords:
Cc:

Description

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.

Attachments

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as new
as The resolution will be set. Next status will be 'closed'
to The owner will be changed from xi. Next status will be 'new'
The owner will be changed from xi to anonymous. Next status will be 'assigned'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.