code: def int_to_float(n):
      """
      Correctly-rounded integer-to-float conversion.
  
      """
      # Constants, depending only on the floating-point format in use.
      # We use an extra 2 bits of precision for rounding purposes.
      PRECISION = sys.float_info.mant_dig + 2
      SHIFT_MAX = sys.float_info.max_exp - PRECISION
      Q_MAX = 1 << PRECISION
      ROUND_HALF_TO_EVEN_CORRECTION = [0, -1, -2, 1, 0, -1, 2, 1]
  
      # Reduce to the case where n is positive.
      if n == 0:
          return 0.0
      elif n < 0:
          return -int_to_float(-n)
  
      # Convert n to a 'floating-point' number q * 2**shift, where q is an
      # integer with 'PRECISION' significant bits.  When shifting n to create q,
      # the least significant bit of q is treated as 'sticky'.  That is, the
      # least significant bit of q is set if either the corresponding bit of n
      # was already set, or any one of the bits of n lost in the shift was set.
      shift = n.bit_length() - PRECISION
      q = (
          n << -shift
          if shift < 0
          else (n >> shift) | bool(n & ~(-1 << shift))
      )
  
      # Round half to even (actually rounds to the nearest multiple of 4,
      # rounding ties to a multiple of 8).
      q += ROUND_HALF_TO_EVEN_CORRECTION[q & 7]
  
      # Detect overflow.
      if shift + (q == Q_MAX) > SHIFT_MAX:
          raise OverflowError("integer too large to convert to float")
  
      # Checks: q is exactly representable, and q**2**shift doesn't overflow.
      assert q % 4 == 0 and q // 4 <= 2 ** (sys.float_info.mant_dig)
      assert q * 2**shift <= sys.float_info.max
  
      # Some circularity here, since float(q) is doing an int-to-float
      # conversion.  But here q is of bounded size, and is exactly representable
      # as a float.  In a low-level C-like language, this operation would be a
      # simple cast (e.g., from unsigned long long to double).
      return math.ldexp(float(q), shift)
  
imports: import unittest
  from test import support
  import sys
  import random
  import math
  import array
label_desc: Use image node_id 1 for calling a global function with example usage: int_to_float(n) and returns: math, int, unknown