Back to index

moin  1.9.0~rc2
Classes | Functions | Variables
MoinMoin.support.xappy.searchconnection Namespace Reference

Classes

class  SearchResult
class  SearchResultIter
class  SearchResults
class  SearchConnection

Functions

def _get_significant_digits

Variables

string __docformat__ = "restructuredtext en"

Function Documentation

def MoinMoin.support.xappy.searchconnection._get_significant_digits (   value,
  lower,
  upper 
) [private]
Get the significant digits of value which are constrained by the
(inclusive) lower and upper bounds.

If there are no significant digits which are definitely within the
bounds, exactly one significant digit will be returned in the result.

>>> _get_significant_digits(15,15,15)
15
>>> _get_significant_digits(15,15,17)
20
>>> _get_significant_digits(4777,208,6000)
5000
>>> _get_significant_digits(4777,4755,4790)
4800
>>> _get_significant_digits(4707,4695,4710)
4700
>>> _get_significant_digits(4719,4717,4727)
4720
>>> _get_significant_digits(0,0,0)
0
>>> _get_significant_digits(9,9,10)
9
>>> _get_significant_digits(9,9,100)
9

Definition at line 184 of file searchconnection.py.

00184 
00185 def _get_significant_digits(value, lower, upper):
00186     """Get the significant digits of value which are constrained by the
00187     (inclusive) lower and upper bounds.
00188 
00189     If there are no significant digits which are definitely within the
00190     bounds, exactly one significant digit will be returned in the result.
00191 
00192     >>> _get_significant_digits(15,15,15)
00193     15
00194     >>> _get_significant_digits(15,15,17)
00195     20
00196     >>> _get_significant_digits(4777,208,6000)
00197     5000
00198     >>> _get_significant_digits(4777,4755,4790)
00199     4800
00200     >>> _get_significant_digits(4707,4695,4710)
00201     4700
00202     >>> _get_significant_digits(4719,4717,4727)
00203     4720
00204     >>> _get_significant_digits(0,0,0)
00205     0
00206     >>> _get_significant_digits(9,9,10)
00207     9
00208     >>> _get_significant_digits(9,9,100)
00209     9
00210 
00211     """
00212     assert(lower <= value)
00213     assert(value <= upper)
00214     diff = upper - lower
00215 
00216     # Get the first power of 10 greater than the difference.
00217     # This corresponds to the magnitude of the smallest significant digit.
00218     if diff == 0:
00219         pos_pow_10 = 1
00220     else:
00221         pos_pow_10 = int(10 ** math.ceil(math.log10(diff)))
00222 
00223     # Special case for situation where we don't have any significant digits:
00224     # get the magnitude of the most significant digit in value.
00225     if pos_pow_10 > value:
00226         if value == 0:
00227             pos_pow_10 = 1
00228         else:
00229             pos_pow_10 = int(10 ** math.floor(math.log10(value)))
00230 
00231     # Return the value, rounded to the nearest multiple of pos_pow_10
00232     return ((value + pos_pow_10 // 2) // pos_pow_10) * pos_pow_10

Here is the caller graph for this function:


Variable Documentation

Definition at line 21 of file searchconnection.py.