Skip to content

Commit

Permalink
Change order of drop-precision-bits and shrink-integer
Browse files Browse the repository at this point in the history
  • Loading branch information
jobh committed Aug 5, 2023
1 parent b47c8a3 commit ffc4703
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,8 @@ def run_step(self):
# change that would require shifting the exponent while not changing
# the float value much.

if self.consider(int(self.current)):
self.debug("Just an integer now")
self.delegate(Integer, convert_to=int, convert_from=float)
return

# Try dropping precision bits by rounding the scaled value. We try
# values ordered from least-precise (integer) to more precise, ie.
# First, try dropping precision bits by rounding the scaled value. We
# try values ordered from least-precise (integer) to more precise, ie.
# approximate lexicographical order. Once we find an acceptable shrink,
# self.consider discards the remaining attempts early and skips test
# invocation. The loop count sets max fractional bits to keep, and is a
Expand All @@ -82,6 +77,11 @@ def run_step(self):
for truncate in [math.floor, math.ceil]:
self.consider(truncate(scaled) / 2**p)

if self.consider(int(self.current)):
self.debug("Just an integer now")
self.delegate(Integer, convert_to=int, convert_from=float)
return

# Now try to minimize the top part of the fraction as an integer. This
# basically splits the float as k + x with 0 <= x < 1 and minimizes
# k as an integer, but without the precision issues that would have.
Expand Down

0 comments on commit ffc4703

Please sign in to comment.