Skip to content

Commit 14a5656

Browse files
committed
Use tuple instead of bytes
1 parent 11085e7 commit 14a5656

File tree

1 file changed

+3
-5
lines changed
  • hypothesis-python/src/hypothesis/internal/conjecture/shrinking

1 file changed

+3
-5
lines changed

hypothesis-python/src/hypothesis/internal/conjecture/shrinking/floats.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@
99
# obtain one at https://mozilla.org/MPL/2.0/.
1010

1111
import math
12-
import struct
1312
import sys
1413

1514
from hypothesis.internal.conjecture.floats import float_to_lex
1615
from hypothesis.internal.conjecture.shrinking.common import Shrinker
1716
from hypothesis.internal.conjecture.shrinking.integer import Integer
18-
from hypothesis.internal.floats import MAX_PRECISE_INTEGER
17+
from hypothesis.internal.floats import MAX_PRECISE_INTEGER, float_to_int
1918

2019

2120
class Float(Shrinker):
@@ -25,9 +24,8 @@ def setup(self):
2524
def make_canonical(self, f):
2625
if math.isnan(f):
2726
# Distinguish different NaN bit patterns, while making each equal to itself.
28-
# Returning bytes instead of integer (float_to_int) avoids accidental
29-
# equality with valid large floats.
30-
return struct.pack("d", f)
27+
# Wrap in tuple to avoid potential collision with (huge) finite floats.
28+
return ("nan", float_to_int(f))
3129
return f
3230

3331
def check_invariants(self, value):

0 commit comments

Comments
 (0)