当前位置: 首页>>代码示例>>Python>>正文


Python math.fmod方法代码示例

本文整理汇总了Python中math.fmod方法的典型用法代码示例。如果您正苦于以下问题:Python math.fmod方法的具体用法?Python math.fmod怎么用?Python math.fmod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在math的用法示例。


在下文中一共展示了math.fmod方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: advance_wrap

# 需要导入模块: import math [as 别名]
# 或者: from math import fmod [as 别名]
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)) 
开发者ID:qedus,项目名称:sphere,代码行数:26,代码来源:sphere.py

示例2: MapToMinusPiToPi

# 需要导入模块: import math [as 别名]
# 或者: from math import fmod [as 别名]
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 
开发者ID:utra-robosoccer,项目名称:soccer-matlab,代码行数:18,代码来源:minitaur.py

示例3: function

# 需要导入模块: import math [as 别名]
# 或者: from math import fmod [as 别名]
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 
开发者ID:NiaOrg,项目名称:NiaPy,代码行数:27,代码来源:schwefel.py

示例4: testFmod

# 需要导入模块: import math [as 别名]
# 或者: from math import fmod [as 别名]
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) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:23,代码来源:test_math.py

示例5: advance_wrap

# 需要导入模块: import math [as 别名]
# 或者: from math import fmod [as 别名]
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)) 
开发者ID:sidewalklabs,项目名称:s2sphere,代码行数:26,代码来源:sphere.py

示例6: split_array

# 需要导入模块: import math [as 别名]
# 或者: from math import fmod [as 别名]
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 
开发者ID:Novartis,项目名称:yap,代码行数:22,代码来源:yap_tools.py

示例7: _adjustHueNp

# 需要导入模块: import math [as 别名]
# 或者: from math import fmod [as 别名]
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) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:19,代码来源:image_ops_test.py

示例8: testFmod

# 需要导入模块: import math [as 别名]
# 或者: from math import fmod [as 别名]
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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:23,代码来源:test_math.py

示例9: arc_to_bulge

# 需要导入模块: import math [as 别名]
# 或者: from math import fmod [as 别名]
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 
开发者ID:mozman,项目名称:ezdxf,代码行数:22,代码来源:bulge.py

示例10: draw

# 需要导入模块: import math [as 别名]
# 或者: from math import fmod [as 别名]
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) 
开发者ID:Contraz,项目名称:demosys-py,代码行数:21,代码来源:effects.py

示例11: _round_to_significant

# 需要导入模块: import math [as 别名]
# 或者: from math import fmod [as 别名]
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 
开发者ID:highfestiva,项目名称:finplot,代码行数:20,代码来源:__init__.py

示例12: sincosd

# 需要导入模块: import math [as 别名]
# 或者: from math import fmod [as 别名]
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 
开发者ID:NationalSecurityAgency,项目名称:qgis-shapetools-plugin,代码行数:22,代码来源:geomath.py

示例13: getOutOfBoundsAngleInPolygon

# 需要导入模块: import math [as 别名]
# 或者: from math import fmod [as 别名]
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) 
开发者ID:dsgoficial,项目名称:DsgTools,代码行数:23,代码来源:geometryHandler.py

示例14: mod_to_UC

# 需要导入模块: import math [as 别名]
# 或者: from math import fmod [as 别名]
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) 
开发者ID:peteboyd,项目名称:lammps_interface,代码行数:19,代码来源:structure_data.py

示例15: MapToMinusPiToPi

# 需要导入模块: import math [as 别名]
# 或者: from math import fmod [as 别名]
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 
开发者ID:nicrusso7,项目名称:rex-gym,代码行数:18,代码来源:rex.py


注:本文中的math.fmod方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。