old_contents: import numpy as np
  import math
  from numba import cuda
  from numba.cuda.testing import unittest, CUDATestCase
  
  
  def simple_frexp(aryx, aryexp, arg):
      aryx[0], aryexp[0] = math.frexp(arg)
  
  
  def simple_ldexp(aryx, arg, exp):
      aryx[0] = math.ldexp(arg, exp)
  
  
  class TestCudaFrexpLdexp(CUDATestCase):
      def test_frexp_f4(self):
          compiled = cuda.jit("void(f4[:], int32[:], f4)")(simple_frexp)
          arg = 3.1415
          aryx = np.zeros(1, dtype=np.float32)
          aryexp = np.zeros(1, dtype=np.int32)
          compiled[1, 1](aryx, aryexp, arg)
          np.testing.assert_array_equal(aryx, np.float32(0.785375))
          self.assertEquals(aryexp, 2)
  
      def test_ldexp_f4(self):
          compiled = cuda.jit("void(f4[:], f4, int32)")(simple_ldexp)
          arg = 0.785375
          exp = 2
          aryx = np.zeros(1, dtype=np.float32)
          compiled[1, 1](aryx, arg, exp)
          np.testing.assert_array_equal(aryx, np.float32(3.1415))
  
      def test_frexp_f8(self):
          compiled = cuda.jit("void(f8[:], int32[:], f8)")(simple_frexp)
          arg = 0.017
          aryx = np.zeros(1, dtype=np.float64)
          aryexp = np.zeros(1, dtype=np.int32)
          compiled[1, 1](aryx, aryexp, arg)
          np.testing.assert_array_equal(aryx, np.float64(0.544))
          self.assertEquals(aryexp, -5)
  
      def test_ldexp_f8(self):
          compiled = cuda.jit("void(f8[:], f8, int32)")(simple_ldexp)
          arg = 0.544
          exp = -5
          aryx = np.zeros(1, dtype=np.float64)
          compiled[1, 1](aryx, arg, exp)
          np.testing.assert_array_equal(aryx, np.float64(0.017))
  
  
  if __name__ == '__main__':
      unittest.main()
  
new_contents: import numpy as np
  import math
  from numba import cuda
  from numba.types import float32, float64, int32
  from numba.cuda.testing import unittest, CUDATestCase
  
  
  def simple_frexp(x, exp, arg):
      x[0], exp[0] = math.frexp(arg)
  
  
  def simple_ldexp(val, arg, exp):
      val[0] = math.ldexp(arg, exp)
  
  
  class TestCudaFrexpLdexp(CUDATestCase):
      def template_test_frexp_ldexp(self, value, npyty, npmty):
          frexp_kernel = cuda.jit((npmty[:], int32[:], npmty))(simple_frexp)
  
          arg = npyty(value)
          x = np.empty(1, dtype=npyty)
          xneg = np.empty_like(x)
          exp = np.empty_like(x, dtype=np.int32)
          npx, npexp = np.frexp(arg)
  
          frexp_kernel[1, 1](x, exp, arg)
  
          np.testing.assert_array_equal(x, npx)
          self.assertEquals(exp, npexp)
  
          frexp_kernel[1, 1](xneg, exp, -arg)
  
          np.testing.assert_array_equal(xneg, -npx)
          self.assertEquals(exp, npexp)
  
          ldexp_kernel = cuda.jit((npmty[:], npmty, int32))(simple_ldexp)
  
          val = np.empty(1, dtype=npyty)
  
          ldexp_kernel[1, 1](val, x.item(), exp.item())
  
          np.testing.assert_array_equal(val, np.ldexp(x, exp))
          np.testing.assert_array_equal(val, arg)  # roundtrip
  
          ldexp_kernel[1, 1](val, xneg.item(), exp.item())
  
          np.testing.assert_array_equal(val, np.ldexp(xneg, exp))
          np.testing.assert_array_equal(val, -arg)  # roundtrip
  
      def test_ldexp_frexp(self):
          for value in [0., 3.1e-10, 0.785375, 2., 1.3e10]:
              self.template_test_frexp_ldexp(value, np.float32, float32)
              self.template_test_frexp_ldexp(value, np.float64, float64)
  
  
  if __name__ == '__main__':
      unittest.main()
  
subject: Rewrite frexp-ldexp tests with a template