Skip to content

Commit 33c4ea1

Browse files
committed
Stop using infinity for float/double bounds
Instead, we use Float/Double.MAX_VALUE.
1 parent 91d9733 commit 33c4ea1

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/scyjava/_types.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def numeric_bounds(the_type: type) -> Union[Tuple[int, int], Tuple[float, float]
284284
"""
285285
Get the minimum and maximum values for the given numeric type.
286286
For example, a Java long returns (int(Long.MIN_VALUE), int(Long.MAX_VALUE)),
287-
whereas a Java double returns (float("-inf"), float("inf")).
287+
whereas a Java double returns (double(-Double.MAX_VALUE), double(Double.MAX_VALUE)).
288288
289289
:param the_type: The type whose minimum and maximum values are needed.
290290
:return:
@@ -307,8 +307,13 @@ def numeric_bounds(the_type: type) -> Union[Tuple[int, int], Tuple[float, float]
307307
Long = jimport("java.lang.Long")
308308
return int(Long.MIN_VALUE), int(Long.MAX_VALUE)
309309

310-
if is_jfloat(the_type) or is_jdouble(the_type):
311-
return float("-inf"), float("inf")
310+
if is_jfloat(the_type):
311+
Float = jimport("java.lang.Float")
312+
return float(-Float.MAX_VALUE), float(Float.MAX_VALUE)
313+
314+
if is_jdouble(the_type):
315+
Double = jimport("java.lang.Double")
316+
return float(-Double.MAX_VALUE), float(Double.MAX_VALUE)
312317

313318
return None, None
314319

tests/test_types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ def test_numeric_bounds(self):
2222
assert (-2147483648, 2147483647) == numeric_bounds(type(v_int))
2323
assert (-9223372036854775808, 9223372036854775807) == numeric_bounds(type(v_long))
2424
assert (None, None) == numeric_bounds(type(v_bigint))
25-
assert (float("-inf"), float("inf")) == numeric_bounds(type(v_float))
26-
assert (float("-inf"), float("inf")) == numeric_bounds(type(v_double))
25+
assert (-3.4028234663852886e+38, 3.4028234663852886e+38) == numeric_bounds(type(v_float))
26+
assert (-1.7976931348623157e+308, 1.7976931348623157e+308) == numeric_bounds(type(v_double))
2727
assert (None, None) == numeric_bounds(type(v_bigdec))

0 commit comments

Comments
 (0)