Skip to content

Commit 006b979

Browse files
committed
add case for negative exponent truncation, add guard for the mantissa
1 parent 56ff0b5 commit 006b979

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

bayes_opt/logger.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ def _format_number(self, x: float) -> str:
9797
if width > 0:
9898
result += s[dot_pos : dot_pos + width]
9999
else:
100-
result += s[:width]
100+
head = s[:e_pos] if "e" in s else s
101+
result += head[:width]
101102
if "e" in s:
102103
result += end
103104
result = result.ljust(self._default_cell_size)

tests/test_logger.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ def test_format_number():
9191
formatted = logger._format_number(sci_float)
9292
assert formatted == "1.111e-05"
9393

94-
# Test negative scientific notation truncation
94+
sci_float_neg = -1.11111111e-5
95+
formatted = logger._format_number(sci_float_neg)
96+
assert formatted == "-1.11e-05"
97+
9598
sci_float = -12345678901234.5678901234
9699
formatted = logger._format_number(sci_float)
97100
assert len(formatted) == logger._default_cell_size

0 commit comments

Comments
 (0)