code: def test_floor_exact(max_digits):
      max_digits(4950)  # max longdouble is ~10**4932
  
      to_test = IEEE_floats + [float]
      try:
          type_info(np.longdouble)["nmant"]
      except FloatingError:
          # Significand bit count not reliable, don't test long double
          pass
      else:
          to_test.append(np.longdouble)
      # When numbers go above int64 - I believe, numpy comparisons break down,
      # so we have to cast to int before comparison
      int_flex = lambda x, t: int(floor_exact(x, t))
      int_ceex = lambda x, t: int(ceil_exact(x, t))
      for t in to_test:
          # A number bigger than the range returns the max
          info = type_info(t)
          assert floor_exact(10**4933, t) == np.inf
          assert ceil_exact(10**4933, t) == np.inf
          # A number more negative returns -inf
          assert floor_exact(-(10**4933), t) == -np.inf
          assert ceil_exact(-(10**4933), t) == -np.inf
          # Check around end of integer precision
          nmant = info["nmant"]
          for i in range(nmant + 1):
              iv = 2**i
              # up to 2**nmant should be exactly representable
              for func in (int_flex, int_ceex):
                  assert func(iv, t) == iv
                  assert func(-iv, t) == -iv
                  assert func(iv - 1, t) == iv - 1
                  assert func(-iv + 1, t) == -iv + 1
          if t is np.longdouble and (
              on_powerpc() or longdouble_precision_improved()
          ):
              # The nmant value for longdouble on PPC appears to be conservative,
              # so that the tests for behavior above the nmant range fail.
              # windows longdouble can change from float64 to Intel80 in some
              # situations, in which case nmant will not be correct
              continue
          # Confirm to ourselves that 2**(nmant+1) can't be exactly represented
          iv = 2 ** (nmant + 1)
          assert int_flex(iv + 1, t) == iv
          assert int_ceex(iv + 1, t) == iv + 2
          # negatives
          assert int_flex(-iv - 1, t) == -iv - 2
          assert int_ceex(-iv - 1, t) == -iv
          # The gap in representable numbers is 2 above 2**(nmant+1), 4 above
          # 2**(nmant+2), and so on.
          for i in range(5):
              iv = 2 ** (nmant + 1 + i)
              gap = 2 ** (i + 1)
              assert int(t(iv) + t(gap)) == iv + gap
              for j in range(1, gap):
                  assert int_flex(iv + j, t) == iv
                  assert int_flex(iv + gap + j, t) == iv + gap
                  assert int_ceex(iv + j, t) == iv + gap
                  assert int_ceex(iv + gap + j, t) == iv + 2 * gap
              # negatives
              for j in range(1, gap):
                  assert int_flex(-iv - j, t) == -iv - gap
                  assert int_flex(-iv - gap - j, t) == -iv - 2 * gap
                  assert int_ceex(-iv - j, t) == -iv
                  assert int_ceex(-iv - gap - j, t) == -iv - gap
  
file_path: nibabel/nibabel/tests/test_floating.py
imports: import sys
  from contextlib import nullcontext
  import numpy
  import pytest
  from packaging.version import Version
  from ..casting import FloatingError, _check_maxexp, _check_nmant, ceil_exact, floor_exact, floor_log2, have_binary128, longdouble_precision_improved, ok_floats, on_powerpc, sctypes, type_info
  from ..testing import suppress_warnings
label_desc: Use image node_id 9 for calling a global function with example usage: test_floor_exact(max_digits) without return types