MCPcopy Create free account
hub / github.com/apache/arrow / largest_scaled_float_not_above

Function largest_scaled_float_not_above

python/pyarrow/tests/test_compute.py:2321–2334  ·  view source on GitHub ↗

Find the largest float f such as `f * 10**scale <= val`

(val, scale)

Source from the content-addressed store, hash-verified

2319
2320
2321def largest_scaled_float_not_above(val, scale):
2322 """
2323 Find the largest float f such as `f * 10**scale <= val`
2324 """
2325 assert val >= 0
2326 assert scale >= 0
2327 float_val = float(val) / 10**scale
2328 if float_val * 10**scale > val:
2329 # Take the float just below... it *should* satisfy
2330 float_val = np.nextafter(float_val, 0.0)
2331 if float_val * 10**scale > val:
2332 float_val = np.nextafter(float_val, 0.0)
2333 assert float_val * 10**scale <= val
2334 return float_val
2335
2336
2337def scaled_float(int_val, scale):

Calls

no outgoing calls

Tested by

no test coverage detected