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


Python Math.sum方法代码示例

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


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

示例1: Add

# 需要导入模块: from geographiclib.geomath import Math [as 别名]
# 或者: from geographiclib.geomath.Math import sum [as 别名]
 def Add(self, y):
   """Add a value"""
   # Here's Shewchuk's solution...
   # hold exact sum as [s, t, u]
   y, u = Math.sum(y, self._t)             # Accumulate starting at
   self._s, self._t = Math.sum(y, self._s) # least significant end
   # Start is _s, _t decreasing and non-adjacent.  Sum is now (s + t + u)
   # exactly with s, t, u non-adjacent and in decreasing order (except
   # for possible zeros).  The following code tries to normalize the
   # result.  Ideally, we want _s = round(s+t+u) and _u = round(s+t+u -
   # _s).  The follow does an approximate job (and maintains the
   # decreasing non-adjacent property).  Here are two "failures" using
   # 3-bit floats:
   #
   # Case 1: _s is not equal to round(s+t+u) -- off by 1 ulp
   # [12, -1] - 8 -> [4, 0, -1] -> [4, -1] = 3 should be [3, 0] = 3
   #
   # Case 2: _s+_t is not as close to s+t+u as it shold be
   # [64, 5] + 4 -> [64, 8, 1] -> [64,  8] = 72 (off by 1)
   #                    should be [80, -7] = 73 (exact)
   #
   # "Fixing" these problems is probably not worth the expense.  The
   # representation inevitably leads to small errors in the accumulated
   # values.  The additional errors illustrated here amount to 1 ulp of
   # the less significant word during each addition to the Accumulator
   # and an additional possible error of 1 ulp in the reported sum.
   #
   # Incidentally, the "ideal" representation described above is not
   # canonical, because _s = round(_s + _t) may not be true.  For
   # example, with 3-bit floats:
   #
   # [128, 16] + 1 -> [160, -16] -- 160 = round(145).
   # But [160, 0] - 16 -> [128, 16] -- 128 = round(144).
   #
   if self._s == 0:            # This implies t == 0,
     self._s = u               # so result is u
   else:
     self._t += u              # otherwise just accumulate u to t.
开发者ID:codenotes,项目名称:GeoGraphicsLib,代码行数:40,代码来源:accumulator.py


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