本文整理匯總了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))
示例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
示例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
示例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)
示例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))
示例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
示例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)
示例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)
示例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
示例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)
示例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
示例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
示例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)
示例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)
示例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