Python math.fmod() Examples

The following are 30 code examples for showing how to use math.fmod(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module math , or try the search function .

Example 1
Project: soccer-matlab   Author: utra-robosoccer   File: minitaur.py    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
def MapToMinusPiToPi(angles):
  """Maps a list of angles to [-pi, pi].

  Args:
    angles: A list of angles in rad.
  Returns:
    A list of angle mapped to [-pi, pi].
  """
  mapped_angles = copy.deepcopy(angles)
  for i in range(len(angles)):
    mapped_angles[i] = math.fmod(angles[i], TWO_PI)
    if mapped_angles[i] >= math.pi:
      mapped_angles[i] -= TWO_PI
    elif mapped_angles[i] < -math.pi:
      mapped_angles[i] += TWO_PI
  return mapped_angles 
Example 2
Project: sphere   Author: qedus   File: sphere.py    License: MIT License 6 votes vote down vote up
def advance_wrap(self, steps):
        assert self.is_valid()
        if steps == 0:
            return self

        step_shift = 2 * (self.__class__.MAX_LEVEL - self.level()) + 1
        if steps < 0:
            min_steps = -(self.id() >> step_shift)
            if steps < min_steps:
                step_wrap = self.__class__.WRAP_OFFSET >> step_shift
                # cannot use steps %= step_wrap as Python % different to C++
                steps = long(math.fmod(steps, step_wrap))
                if steps < min_steps:
                    steps += step_wrap
        else:
            max_steps = (self.__class__.WRAP_OFFSET - self.id()) >> step_shift
            if steps > max_steps:
                step_wrap = self.__class__.WRAP_OFFSET >> step_shift
                # cannot use steps %= step_wrap as Python % different to C++
                steps = long(math.fmod(steps, step_wrap))
                if steps > max_steps:
                    steps -= step_wrap

        return self.__class__(self.id() + (steps << step_shift)) 
Example 3
Project: NiaPy   Author: NiaOrg   File: schwefel.py    License: MIT License 6 votes vote down vote up
def function(self):
		r"""Return benchmark evaluation function.

		Returns:
			Callable[[int, Union[int, float, List[int, float], numpy.ndarray]], float]: Fitness function
		"""
		def g(z, D):
			if z > 500: return (500 - fmod(z, 500)) * sin(sqrt(fabs(500 - fmod(z, 500)))) - (z - 500) ** 2 / (10000 * D)
			elif z < -500: return (fmod(z, 500) - 500) * sin(sqrt(fabs(fmod(z, 500) - 500))) + (z - 500) ** 2 / (10000 * D)
			return z * sin(fabs(z) ** (1 / 2))
		def h(x, D): return g(x + 420.9687462275036, D)
		def f(D, sol):
			r"""Fitness function.

			Args:
				D (int): Dimensionality of the problem
				sol (Union[int, float, List[int, float], numpy.ndarray]): Solution to check.

			Returns:
				float: Fitness value for the solution.
			"""
			val = 0.0
			for i in range(D): val += h(sol[i], D)
			return 418.9829 * D - val
		return f 
Example 4
Project: ironpython2   Author: IronLanguages   File: test_math.py    License: Apache License 2.0 6 votes vote down vote up
def testFmod(self):
        self.assertRaises(TypeError, math.fmod)
        self.ftest('fmod(10,1)', math.fmod(10,1), 0)
        self.ftest('fmod(10,0.5)', math.fmod(10,0.5), 0)
        self.ftest('fmod(10,1.5)', math.fmod(10,1.5), 1)
        self.ftest('fmod(-10,1)', math.fmod(-10,1), 0)
        self.ftest('fmod(-10,0.5)', math.fmod(-10,0.5), 0)
        self.ftest('fmod(-10,1.5)', math.fmod(-10,1.5), -1)
        self.assertTrue(math.isnan(math.fmod(NAN, 1.)))
        self.assertTrue(math.isnan(math.fmod(1., NAN)))
        self.assertTrue(math.isnan(math.fmod(NAN, NAN)))
        self.assertRaises(ValueError, math.fmod, 1., 0.)
        self.assertRaises(ValueError, math.fmod, INF, 1.)
        self.assertRaises(ValueError, math.fmod, NINF, 1.)
        self.assertRaises(ValueError, math.fmod, INF, 0.)
        self.assertEqual(math.fmod(3.0, INF), 3.0)
        self.assertEqual(math.fmod(-3.0, INF), -3.0)
        self.assertEqual(math.fmod(3.0, NINF), 3.0)
        self.assertEqual(math.fmod(-3.0, NINF), -3.0)
        self.assertEqual(math.fmod(0.0, 3.0), 0.0)
        self.assertEqual(math.fmod(0.0, NINF), 0.0) 
Example 5
Project: BinderFilter   Author: dxwu   File: test_math.py    License: MIT License 6 votes vote down vote up
def testFmod(self):
        self.assertRaises(TypeError, math.fmod)
        self.ftest('fmod(10,1)', math.fmod(10,1), 0)
        self.ftest('fmod(10,0.5)', math.fmod(10,0.5), 0)
        self.ftest('fmod(10,1.5)', math.fmod(10,1.5), 1)
        self.ftest('fmod(-10,1)', math.fmod(-10,1), 0)
        self.ftest('fmod(-10,0.5)', math.fmod(-10,0.5), 0)
        self.ftest('fmod(-10,1.5)', math.fmod(-10,1.5), -1)
        self.assertTrue(math.isnan(math.fmod(NAN, 1.)))
        self.assertTrue(math.isnan(math.fmod(1., NAN)))
        self.assertTrue(math.isnan(math.fmod(NAN, NAN)))
        self.assertRaises(ValueError, math.fmod, 1., 0.)
        self.assertRaises(ValueError, math.fmod, INF, 1.)
        self.assertRaises(ValueError, math.fmod, NINF, 1.)
        self.assertRaises(ValueError, math.fmod, INF, 0.)
        self.assertEqual(math.fmod(3.0, INF), 3.0)
        self.assertEqual(math.fmod(-3.0, INF), -3.0)
        self.assertEqual(math.fmod(3.0, NINF), 3.0)
        self.assertEqual(math.fmod(-3.0, NINF), -3.0)
        self.assertEqual(math.fmod(0.0, 3.0), 0.0)
        self.assertEqual(math.fmod(0.0, NINF), 0.0) 
Example 6
Project: oss-ftp   Author: aliyun   File: test_math.py    License: MIT License 6 votes vote down vote up
def testFmod(self):
        self.assertRaises(TypeError, math.fmod)
        self.ftest('fmod(10,1)', math.fmod(10,1), 0)
        self.ftest('fmod(10,0.5)', math.fmod(10,0.5), 0)
        self.ftest('fmod(10,1.5)', math.fmod(10,1.5), 1)
        self.ftest('fmod(-10,1)', math.fmod(-10,1), 0)
        self.ftest('fmod(-10,0.5)', math.fmod(-10,0.5), 0)
        self.ftest('fmod(-10,1.5)', math.fmod(-10,1.5), -1)
        self.assertTrue(math.isnan(math.fmod(NAN, 1.)))
        self.assertTrue(math.isnan(math.fmod(1., NAN)))
        self.assertTrue(math.isnan(math.fmod(NAN, NAN)))
        self.assertRaises(ValueError, math.fmod, 1., 0.)
        self.assertRaises(ValueError, math.fmod, INF, 1.)
        self.assertRaises(ValueError, math.fmod, NINF, 1.)
        self.assertRaises(ValueError, math.fmod, INF, 0.)
        self.assertEqual(math.fmod(3.0, INF), 3.0)
        self.assertEqual(math.fmod(-3.0, INF), -3.0)
        self.assertEqual(math.fmod(3.0, NINF), 3.0)
        self.assertEqual(math.fmod(-3.0, NINF), -3.0)
        self.assertEqual(math.fmod(0.0, 3.0), 0.0)
        self.assertEqual(math.fmod(0.0, NINF), 0.0) 
Example 7
Project: s2sphere   Author: sidewalklabs   File: sphere.py    License: MIT License 6 votes vote down vote up
def advance_wrap(self, steps):
        assert self.is_valid()
        if steps == 0:
            return self

        step_shift = 2 * (self.__class__.MAX_LEVEL - self.level()) + 1
        if steps < 0:
            min_steps = -(self.id() >> step_shift)
            if steps < min_steps:
                step_wrap = self.__class__.WRAP_OFFSET >> step_shift
                # cannot use steps %= step_wrap as Python % different to C++
                steps = int(math.fmod(steps, step_wrap))
                if steps < min_steps:
                    steps += step_wrap
        else:
            max_steps = (self.__class__.WRAP_OFFSET - self.id()) >> step_shift
            if steps > max_steps:
                step_wrap = self.__class__.WRAP_OFFSET >> step_shift
                # cannot use steps %= step_wrap as Python % different to C++
                steps = int(math.fmod(steps, step_wrap))
                if steps > max_steps:
                    steps -= step_wrap

        return self.__class__(self.id() + (steps << step_shift)) 
Example 8
Project: yap   Author: Novartis   File: yap_tools.py    License: Apache License 2.0 6 votes vote down vote up
def split_array(totnum,nprocs,lpp,myrank):
    """ Returns the indices of the chunk(of the input file) to be split based on the 
        rank of the processor."""
    totnum = totnum/lpp
    n2=int(math.floor(totnum/nprocs))
    remain=int(math.fmod(totnum,nprocs))
    if (myrank < remain) :
        n1=n2+1
        ib1=(myrank)*n1
        ie1=ib1+(n1-1)
    else :
        n1=n2
        ib1=(myrank)*n1+remain
        ie1=ib1+n1-1
    ib=ib1*lpp
    ie=((ie1+1)*lpp)-1
    ret=[]
    ret.append(ib)
    ret.append(ie)
    return ret 
Example 9
Project: yap   Author: Novartis   File: yap_tools.py    License: Apache License 2.0 6 votes vote down vote up
def split_array(totnum,nprocs,lpp,myrank):
    """ Determines how the data must be split based on available resources. """
    totnum = totnum/lpp
    n2=int(math.floor(totnum/nprocs))
    remain=int(math.fmod(totnum,nprocs))
    if (myrank < remain) :
        n1=n2+1
        ib1=(myrank)*n1
        ie1=ib1+(n1-1)
    else :
        n1=n2
        ib1=(myrank)*n1+remain
        ie1=ib1+n1-1
    ib=ib1*lpp
    ie=((ie1+1)*lpp)-1
    ret=[]
    ret.append(ib)
    ret.append(ie)
    return ret 
Example 10
Project: deep_image_model   Author: tobegit3hub   File: image_ops_test.py    License: Apache License 2.0 6 votes vote down vote up
def _adjustHueNp(self, x_np, delta_h):
    self.assertEqual(x_np.shape[-1], 3)
    x_v = x_np.reshape([-1, 3])
    y_v = np.ndarray(x_v.shape, dtype=x_v.dtype)
    channel_count = x_v.shape[0]
    for i in xrange(channel_count):
      r = x_v[i][0]
      g = x_v[i][1]
      b = x_v[i][2]
      h, s, v = colorsys.rgb_to_hsv(r, g, b)
      h += delta_h
      h = math.fmod(h + 10.0, 1.0)
      r, g, b = colorsys.hsv_to_rgb(h, s, v)
      y_v[i][0] = r
      y_v[i][1] = g
      y_v[i][2] = b
    return y_v.reshape(x_np.shape) 
Example 11
Project: Fluid-Designer   Author: Microvellum   File: test_math.py    License: GNU General Public License v3.0 6 votes vote down vote up
def testFmod(self):
        self.assertRaises(TypeError, math.fmod)
        self.ftest('fmod(10, 1)', math.fmod(10, 1), 0.0)
        self.ftest('fmod(10, 0.5)', math.fmod(10, 0.5), 0.0)
        self.ftest('fmod(10, 1.5)', math.fmod(10, 1.5), 1.0)
        self.ftest('fmod(-10, 1)', math.fmod(-10, 1), -0.0)
        self.ftest('fmod(-10, 0.5)', math.fmod(-10, 0.5), -0.0)
        self.ftest('fmod(-10, 1.5)', math.fmod(-10, 1.5), -1.0)
        self.assertTrue(math.isnan(math.fmod(NAN, 1.)))
        self.assertTrue(math.isnan(math.fmod(1., NAN)))
        self.assertTrue(math.isnan(math.fmod(NAN, NAN)))
        self.assertRaises(ValueError, math.fmod, 1., 0.)
        self.assertRaises(ValueError, math.fmod, INF, 1.)
        self.assertRaises(ValueError, math.fmod, NINF, 1.)
        self.assertRaises(ValueError, math.fmod, INF, 0.)
        self.assertEqual(math.fmod(3.0, INF), 3.0)
        self.assertEqual(math.fmod(-3.0, INF), -3.0)
        self.assertEqual(math.fmod(3.0, NINF), 3.0)
        self.assertEqual(math.fmod(-3.0, NINF), -3.0)
        self.assertEqual(math.fmod(0.0, 3.0), 0.0)
        self.assertEqual(math.fmod(0.0, NINF), 0.0) 
Example 12
Project: ironpython3   Author: IronLanguages   File: test_math.py    License: Apache License 2.0 6 votes vote down vote up
def testFmod(self):
        self.assertRaises(TypeError, math.fmod)
        self.ftest('fmod(10, 1)', math.fmod(10, 1), 0.0)
        self.ftest('fmod(10, 0.5)', math.fmod(10, 0.5), 0.0)
        self.ftest('fmod(10, 1.5)', math.fmod(10, 1.5), 1.0)
        self.ftest('fmod(-10, 1)', math.fmod(-10, 1), -0.0)
        self.ftest('fmod(-10, 0.5)', math.fmod(-10, 0.5), -0.0)
        self.ftest('fmod(-10, 1.5)', math.fmod(-10, 1.5), -1.0)
        self.assertTrue(math.isnan(math.fmod(NAN, 1.)))
        self.assertTrue(math.isnan(math.fmod(1., NAN)))
        self.assertTrue(math.isnan(math.fmod(NAN, NAN)))
        self.assertRaises(ValueError, math.fmod, 1., 0.)
        self.assertRaises(ValueError, math.fmod, INF, 1.)
        self.assertRaises(ValueError, math.fmod, NINF, 1.)
        self.assertRaises(ValueError, math.fmod, INF, 0.)
        self.assertEqual(math.fmod(3.0, INF), 3.0)
        self.assertEqual(math.fmod(-3.0, INF), -3.0)
        self.assertEqual(math.fmod(3.0, NINF), 3.0)
        self.assertEqual(math.fmod(-3.0, NINF), -3.0)
        self.assertEqual(math.fmod(0.0, 3.0), 0.0)
        self.assertEqual(math.fmod(0.0, NINF), 0.0) 
Example 13
Project: gcblue   Author: gcblue   File: test_math.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def testFmod(self):
        self.assertRaises(TypeError, math.fmod)
        self.ftest('fmod(10,1)', math.fmod(10,1), 0)
        self.ftest('fmod(10,0.5)', math.fmod(10,0.5), 0)
        self.ftest('fmod(10,1.5)', math.fmod(10,1.5), 1)
        self.ftest('fmod(-10,1)', math.fmod(-10,1), 0)
        self.ftest('fmod(-10,0.5)', math.fmod(-10,0.5), 0)
        self.ftest('fmod(-10,1.5)', math.fmod(-10,1.5), -1)
        self.assertTrue(math.isnan(math.fmod(NAN, 1.)))
        self.assertTrue(math.isnan(math.fmod(1., NAN)))
        self.assertTrue(math.isnan(math.fmod(NAN, NAN)))
        self.assertRaises(ValueError, math.fmod, 1., 0.)
        self.assertRaises(ValueError, math.fmod, INF, 1.)
        self.assertRaises(ValueError, math.fmod, NINF, 1.)
        self.assertRaises(ValueError, math.fmod, INF, 0.)
        self.assertEqual(math.fmod(3.0, INF), 3.0)
        self.assertEqual(math.fmod(-3.0, INF), -3.0)
        self.assertEqual(math.fmod(3.0, NINF), 3.0)
        self.assertEqual(math.fmod(-3.0, NINF), -3.0)
        self.assertEqual(math.fmod(0.0, 3.0), 0.0)
        self.assertEqual(math.fmod(0.0, NINF), 0.0) 
Example 14
Project: ezdxf   Author: mozman   File: bulge.py    License: MIT License 6 votes vote down vote up
def arc_to_bulge(center: 'Vertex', start_angle: float, end_angle: float, radius: float) -> Tuple['Vec2', 'Vec2', float]:
    """
    Returns bulge parameters from arc parameters.

    Args:
        center: circle center point as :class:`Vec2` compatible object
        start_angle: start angle in radians
        end_angle: end angle in radians
        radius: circle radius

    Returns:
        tuple: (start_point, end_point, bulge)

    """
    start_point = polar(center, start_angle, radius)
    end_point = polar(center, end_angle, radius)
    pi2 = math.pi * 2
    a = math.fmod((pi2 + (end_angle - start_angle)), pi2) / 4.
    bulge = math.sin(a) / math.cos(a)
    return start_point, end_point, bulge 
Example 15
Project: demosys-py   Author: Contraz   File: effects.py    License: ISC License 6 votes vote down vote up
def draw(self, time, frametime, target):
        self.ctx.enable_only(moderngl.DEPTH_TEST)

        m_proj = self.create_projection(near=0.1, far=800.0)
        m_mv = self.create_transformation(translation=(0.0, -20.0, -200.0))
        m_mv = matrix44.multiply(m_mv, self.sys_camera.view_matrix)

        self.ctx.patch_vertices = 3
        self.ctx.wireframe = True if math.fmod(time, 5) < 2.5 else False

        self.heightmap.use(location=0)
        self.heights.value = 0
        self.proj_matrix.write(m_proj.astype('f4').tobytes())
        self.mv_matrix.write(m_mv.astype('f4').tobytes())

        self.program['TessLevelInner'].value = self.tess_level
        self.program['TessLevelOuter'].value = self.tess_level

        self.terrain.render(self.program, mode=moderngl.PATCHES) 
Example 16
Project: Project-New-Reign---Nemesis-Main   Author: ShikyoKira   File: test_math.py    License: GNU General Public License v3.0 6 votes vote down vote up
def testFmod(self):
        self.assertRaises(TypeError, math.fmod)
        self.ftest('fmod(10, 1)', math.fmod(10, 1), 0.0)
        self.ftest('fmod(10, 0.5)', math.fmod(10, 0.5), 0.0)
        self.ftest('fmod(10, 1.5)', math.fmod(10, 1.5), 1.0)
        self.ftest('fmod(-10, 1)', math.fmod(-10, 1), -0.0)
        self.ftest('fmod(-10, 0.5)', math.fmod(-10, 0.5), -0.0)
        self.ftest('fmod(-10, 1.5)', math.fmod(-10, 1.5), -1.0)
        self.assertTrue(math.isnan(math.fmod(NAN, 1.)))
        self.assertTrue(math.isnan(math.fmod(1., NAN)))
        self.assertTrue(math.isnan(math.fmod(NAN, NAN)))
        self.assertRaises(ValueError, math.fmod, 1., 0.)
        self.assertRaises(ValueError, math.fmod, INF, 1.)
        self.assertRaises(ValueError, math.fmod, NINF, 1.)
        self.assertRaises(ValueError, math.fmod, INF, 0.)
        self.assertEqual(math.fmod(3.0, INF), 3.0)
        self.assertEqual(math.fmod(-3.0, INF), -3.0)
        self.assertEqual(math.fmod(3.0, NINF), 3.0)
        self.assertEqual(math.fmod(-3.0, NINF), -3.0)
        self.assertEqual(math.fmod(0.0, 3.0), 0.0)
        self.assertEqual(math.fmod(0.0, NINF), 0.0) 
Example 17
Project: finplot   Author: highfestiva   File: __init__.py    License: MIT License 6 votes vote down vote up
def _round_to_significant(rng, rngmax, x, significant_decimals, significant_eps):
    is_highres = rng/significant_eps > 1e2 and (rngmax>1e7 or rngmax<1e-2)
    sd = significant_decimals
    if is_highres and abs(x)>0:
        exp10 = floor(np.log10(abs(x)))
        x = x / (10**exp10)
        sd = min(5, sd+int(np.log10(rngmax)))
        fmt = '%%%i.%ife%%i' % (sd, sd)
        r = fmt % (x, exp10)
    else:
        eps = fmod(x, significant_eps)
        if abs(eps) >= significant_eps/2:
            # round up
            eps -= np.sign(eps)*significant_eps
        x -= eps
        fmt = '%%%i.%if' % (sd, sd)
        r = fmt % x
    return r 
Example 18
Project: qgis-shapetools-plugin   Author: NationalSecurityAgency   File: geomath.py    License: GNU General Public License v2.0 6 votes vote down vote up
def sincosd(x):
    """Compute sine and cosine of x in degrees."""

    r = math.fmod(x, 360)
    q = Math.nan if Math.isnan(r) else int(math.floor(r / 90 + 0.5))
    r -= 90 * q; r = math.radians(r)
    s = math.sin(r); c = math.cos(r)
    q = q % 4
    if q == 1:
      s, c =  c, -s
    elif q == 2:
      s, c = -s, -c
    elif q == 3:
      s, c = -c,  s
    # Remove the minus sign on -0.0 except for sin(-0.0).
    # On Windows 32-bit with python 2.7, math.fmod(-0.0, 360) = +0.0
    # (x, c) here fixes this bug.  See also Math::sincosd in the C++ library.
    # AngNormalize has a similar fix.
    s, c = (x, c) if x == 0 else (0.0+s, 0.0+c)
    return s, c 
Example 19
Project: DsgTools   Author: dsgoficial   File: geometryHandler.py    License: GNU General Public License v2.0 6 votes vote down vote up
def getOutOfBoundsAngleInPolygon(self, feat, part, angle, outOfBoundsList, exactAngleMatch=False, angTol=None):
        angTol = 0.1 if angTol is None else angTol
        for linearRing in part.asPolygon():
            linearRing = self.getClockWiseList(linearRing)
            nVertex = len(linearRing)-1
            def clause(x):
                return x < angle if not exactAngleMatch \
                    else not self.isclose(x, angle, abs_tol=angTol)
            clauseLambda = partial(clause)
            for i in range(nVertex):
                if i == 0:
                    vertexAngle = (linearRing[i].azimuth(linearRing[-2]) - linearRing[i].azimuth(linearRing[i+1]) + 360)
                else:
                    vertexAngle = (linearRing[i].azimuth(linearRing[i-1]) - linearRing[i].azimuth(linearRing[i+1]) + 360)
                vertexAngle = math.fmod(vertexAngle, 360)
                if vertexAngle > 180:
                    # if angle calculated is the outter one
                    vertexAngle = 360 - vertexAngle
                if clauseLambda(vertexAngle):
                    geomDict = {'angle':vertexAngle,'feat_id':feat.id(), 'geom':QgsGeometry.fromPointXY(linearRing[i])}
                    outOfBoundsList.append(geomDict) 
Example 20
Project: lammps_interface   Author: peteboyd   File: structure_data.py    License: MIT License 6 votes vote down vote up
def mod_to_UC(self, num):
        """
        Retrun any fractional coordinate back into the unit cell
        """
        if(hasattr(num,'__iter__')):
            for i in range(len(num)):
                if(num[i] < 0.0):
                    num[i] = 1+math.fmod(num[i], 1.0)
                else:
                    num[i] = math.fmod(num[i], 1.0)

            return num
        else:
            if(num < 0.0):
                num = math.fmod((num*(-1)), 1.0)
            else:
                num = math.fmod(num, 1.0) 
Example 21
Project: CTFCrackTools-V2   Author: Acmesec   File: test_math.py    License: GNU General Public License v3.0 6 votes vote down vote up
def testFmod(self):
        self.assertRaises(TypeError, math.fmod)
        self.ftest('fmod(10,1)', math.fmod(10,1), 0)
        self.ftest('fmod(10,0.5)', math.fmod(10,0.5), 0)
        self.ftest('fmod(10,1.5)', math.fmod(10,1.5), 1)
        self.ftest('fmod(-10,1)', math.fmod(-10,1), 0)
        self.ftest('fmod(-10,0.5)', math.fmod(-10,0.5), 0)
        self.ftest('fmod(-10,1.5)', math.fmod(-10,1.5), -1)
        self.assertTrue(math.isnan(math.fmod(NAN, 1.)))
        self.assertTrue(math.isnan(math.fmod(1., NAN)))
        self.assertTrue(math.isnan(math.fmod(NAN, NAN)))
        self.assertRaises(ValueError, math.fmod, 1., 0.)
        self.assertRaises(ValueError, math.fmod, INF, 1.)
        self.assertRaises(ValueError, math.fmod, NINF, 1.)
        self.assertRaises(ValueError, math.fmod, INF, 0.)
        self.assertEqual(math.fmod(3.0, INF), 3.0)
        self.assertEqual(math.fmod(-3.0, INF), -3.0)
        self.assertEqual(math.fmod(3.0, NINF), 3.0)
        self.assertEqual(math.fmod(-3.0, NINF), -3.0)
        self.assertEqual(math.fmod(0.0, 3.0), 0.0)
        self.assertEqual(math.fmod(0.0, NINF), 0.0) 
Example 22
Project: rex-gym   Author: nicrusso7   File: rex.py    License: Apache License 2.0 6 votes vote down vote up
def MapToMinusPiToPi(angles):
    """Maps a list of angles to [-pi, pi].

      Args:
        angles: A list of angles in rad.
      Returns:
        A list of angle mapped to [-pi, pi].
    """
    mapped_angles = copy.deepcopy(angles)
    for i in range(len(angles)):
        mapped_angles[i] = math.fmod(angles[i], TWO_PI)
        if mapped_angles[i] >= math.pi:
            mapped_angles[i] -= TWO_PI
        elif mapped_angles[i] < -math.pi:
            mapped_angles[i] += TWO_PI
    return mapped_angles 
Example 23
Project: sphere   Author: qedus   File: sphere.py    License: MIT License 5 votes vote down vote up
def __init__(self, deriv):
        super(AreaMetric, self).__init__(deriv, 2)

# like fmod but rounds to nearest integer instead of floor 
Example 24
Project: vnpy_crypto   Author: birforce   File: jdcal.py    License: MIT License 5 votes vote down vote up
def is_leap(year):
    """Leap year or not in the Gregorian calendar."""
    x = math.fmod(year, 4)
    y = math.fmod(year, 100)
    z = math.fmod(year, 400)

    # Divisible by 4 and,
    # either not divisible by 100 or divisible by 400.
    return not x and (y or not z) 
Example 25
Project: Dallinger   Author: Dallinger   File: models.py    License: MIT License 5 votes vote down vote up
def _func(self, x):
        return 75 if (math.fmod(x, 50) <= 25) else 25 
Example 26
Project: perceptron-benchmark   Author: advboxes   File: motion_blur.py    License: Apache License 2.0 5 votes vote down vote up
def motion_Kernel(dim, angle):

        if isinstance(dim, int):
            dim = (dim, dim)
        dim = np.array(dim).astype(int)
        center = (dim - 1) / 2
        kernel = np.zeros(dim)
        angle = math.fmod(angle, 180.0)
        if angle == 90:
            kernel[:, int(center[1])] = 1
            return kernel

        delta_x = 0
        delta_y = 0
        while True:
            if (center[1] + delta_x).is_integer():
                if int(round(center[0] + delta_y)) < 0 or int(round(center[0] + delta_y)) >= dim[0] or int(
                        center[1] + delta_x) < 0 or int(center[1] + delta_x) >= dim[1]:
                    break

                kernel[int(round(center[0] - delta_y)),
                       int(center[1] + delta_x)] = 1
                kernel[int(round(center[0] + delta_y)),
                       int(center[1] - delta_x)] = 1
            delta_x += 0.5
            delta_y = delta_x * math.tan(angle / 180 * np.pi)
        normalizationFactor = np.count_nonzero(kernel)
        kernel /= normalizationFactor
        return kernel 
Example 27
Project: AIT-Core   Author: NASA-AMMOS   File: test_coord.py    License: MIT License 5 votes vote down vote up
def test_eci2geodetic():
    eci = -6.0744*1e6, -1.8289*1e6, 0.6685*1e6
    t = datetime.datetime(2010, 1, 17, 10, 20, 36)
    gmst = dmc.toGMST(t)
    lla = list(coord.eci2geodetic(eci[0], eci[1], eci[2], gmst=gmst))
    lla[0] = math.fmod(lla[0], math.pi * 2)
    lla[1] = math.fmod(lla[1], math.pi * 2)
    assert float_equality(math.degrees(lla[0]), 6.0558200)
    assert float_equality(math.degrees(lla[1]), -75.1266047)
    assert float_equality(lla[2], 978.4703290) 
Example 28
Project: s2sphere   Author: sidewalklabs   File: sphere.py    License: MIT License 5 votes vote down vote up
def drem(x, y):
    """Like fmod but rounds to nearest integer instead of floor."""
    xd = decimal.Decimal(x)
    yd = decimal.Decimal(y)
    return float(xd.remainder_near(yd)) 
Example 29
Project: ufora   Author: ufora   File: pure_math.py    License: Apache License 2.0 5 votes vote down vote up
def __call__(self, x):
        remainder = math.fmod(x, 1)

        if x >= 0:
            return float(x - remainder)

        if remainder == 0:
            return float(x)

        return float(x - remainder - 1) 
Example 30
Project: ufora   Author: ufora   File: pure_math.py    License: Apache License 2.0 5 votes vote down vote up
def __call__(self, x, y):
        if not isinstance(x, float):
            x = float(x)
        if not isinstance(y, float):
            y = float(y)

        return __inline_fora(
            """fun(@unnamed_args:(x, y), *args) {
                   return PyFloat(`fmod(x.@m, y.@m))
                   }"""
            )(x, y)