python类modf()的实例源码

helpers.py 文件源码 项目:core-framework 作者: RedhawkSDR 项目源码 文件源码 阅读 39 收藏 0 点赞 0 评论 0
def iadd(t1, offset):
    fractional, whole = math.modf(offset)
    t1.twsec += whole
    t1.tfsec += fractional
    normalize(t1)
    return t1
timestamp.py 文件源码 项目:core-framework 作者: RedhawkSDR 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def iadd(t1, offset):
    fractional, whole = math.modf(offset)
    t1.twsec += whole
    t1.tfsec += fractional
    normalize(t1)
    return t1
timestamp.py 文件源码 项目:core-framework 作者: RedhawkSDR 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def normalize(tstamp):
    # Get fractional adjustment from whole seconds
    fadj, tstamp.twsec = math.modf(tstamp.twsec)

    # Adjust fractional seconds and get whole seconds adjustment
    tstamp.tfsec, wadj = math.modf(tstamp.tfsec + fadj)

    # If fractional seconds are negative, borrow a second from the whole
    # seconds to make it positive, normalizing to [0,1)
    if (tstamp.tfsec < 0.0):
        tstamp.tfsec += 1.0;
        wadj -= 1.0;

    tstamp.twsec += wadj;
timestamp.py 文件源码 项目:core-framework 作者: RedhawkSDR 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def iadd(t1, offset):
    fractional, whole = math.modf(offset)
    t1.twsec += whole
    t1.tfsec += fractional
    normalize(t1)
    return t1
uckey2shell.py 文件源码 项目:pub1ic_POC 作者: i1ikey0u 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def microtime(get_as_float = False) :
    if get_as_float:
        return time.time()
    else:
        return '%.8f %d' % math.modf(time.time())
daycycle.py 文件源码 项目:piqueserver 作者: piqueserver 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def day_time(connection, value=None):
    if value is not None:
        if not connection.admin:
            return S_NO_RIGHTS
        value = float(value)
        if value < 0.0:
            raise ValueError()
        connection.protocol.current_time = value
        connection.protocol.update_day_color()
    f, i = modf(connection.protocol.current_time)
    return S_TIME_OF_DAY.format(hours=int(i), minutes=int(f * 60))
__init__.py 文件源码 项目:aquests 作者: hansroh 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def suspend (timeout):
    a, b = math.modf (timeout)
    for i in range (int (b)):       
        socketpool.noop ()
        time.sleep (1)
    time.sleep (a)
io_export_pc2.py 文件源码 项目:bpy_lambda 作者: bcongdon 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def get_sampled_frames(start, end, sampling):
    return [math.modf(start + x * sampling) for x in range(int((end - start) / sampling) + 1)]
zahlwort.py 文件源码 项目:spendenquittungsgenerator 作者: moba 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def float2text(number_float):
    cent, euro = modf(number_float)
    cent = round(cent * 100)
    zahlwort = num2text(int(euro)) + ' Euro'
    if (cent > 0):
        zahlwort += ' und ' + num2text(int(cent)) + ' Cent'
    zahlwort = zahlwort[0].upper() + zahlwort[1:]
    return zahlwort
hvutil.py 文件源码 项目:jiveplot 作者: haavee 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def fractionalDayToTime(frac):
    ofrac = frac
    (frac, h) = math.modf(frac*24)
    (frac, m) = math.modf(frac*60)
    (frac, s) = math.modf(frac*60)
    return datetime.time(h, m, s, int(frac*1.0e6))

## Convert time in seconds-since-start-of-day into datetime.time
colz.py 文件源码 项目:colz-python 作者: carloscabo 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def setHue ( self, newhue ):
        """ Modifies hue value of Colz object """
        if  isinstance( newhue, int ):
            newhue /= 360.0
        if newhue > 1.0:
            newhue, whole = math.modf(newhue) # Keep decimal part
        self.h = newhue
        self.hsl[0]  = newhue
        self.hsla[0] = newhue
        self.updateFromHsl()
colz.py 文件源码 项目:colz-python 作者: carloscabo 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def hueLerp ( h1, h2, amt ):
        """ Generic linear interpolation """
        if  isinstance( h1, int ):
            h1 = h1 / 360.0
        if  isinstance( h2, int ):
            h2 = h2 / 360.0
        hue = h1 + Colz.shortHueDist( h1, h2) * amt
        if hue > 1.0:
            hue, whole = math.modf(hue) # Keep decimal part
        if hue < 0.0:
            hue, whole = math.modf(hue) # Keep decimal part
            hue = 1.0 + hue
        return hue
genetic_sort.py 文件源码 项目:ecs 作者: ecs-org 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def next_generation(self):
        next_population = []
        wheel = []
        for permutation in self.population:
            value = self.evaluation[id(permutation)]
            fitness = value / self.avg_value
            fitness_fraction, copies = math.modf(fitness)
            if fitness_fraction:
                wheel.append(permutation)
                wheel.append(permutation)
            if copies == 1:
                next_population.append(permutation)
            elif copies > 1:
                next_population += [permutation] * int(copies)

        # XXX: fractional copies should be placed with a proportinal probability (FMD2)
        next_population += random.sample(wheel, len(self.population) - len(next_population))
        next_population_size = len(next_population)

        # crossover
        crossover_count = int(0.5 * self.crossover_p * next_population_size)
        crossover_indices = random.sample(range(next_population_size), 2 * crossover_count)
        for i in range(crossover_count):
            index_a, index_b = crossover_indices[2*i], crossover_indices[2*i+1]
            next_population[index_a], next_population[index_b] = self.crossover(next_population[index_a], next_population[index_b])

        # mutation
        for mutation, p in self.mutations:
            for index in random.sample(range(next_population_size), int(p * next_population_size)):
                next_population[index] = mutation(next_population[index])

        self.population = next_population
        self.generation_count += 1
        self.evaluate()
game.py 文件源码 项目:AlphaBubble 作者: laurenssam 项目源码 文件源码 阅读 41 收藏 0 点赞 0 评论 0
def addBubbleToTop(bubbleArray, bubble):
    posx = bubble.rect.centerx
    leftSidex = posx - BUBBLERADIUS

    columnDivision = math.modf(float(leftSidex) / float(BUBBLEWIDTH))
    column = int(columnDivision[1])

    if columnDivision[0] < 0.5:
        bubbleArray[0][column] = copy.copy(bubble)
    else:
        column += 1
        bubbleArray[0][column] = copy.copy(bubble)

    row = 0
    return row, column
times.py 文件源码 项目:My-Web-Server-Framework-With-Python2.7 作者: syjsu 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def TimeDelta_or_None(s):
    try:
        h, m, s = s.split(':')
        h, m, s = int(h), int(m), float(s)
        td = timedelta(hours=abs(h), minutes=m, seconds=int(s),
                       microseconds=int(math.modf(s)[0] * 1000000))
        if h < 0:
            return -td
        else:
            return td
    except ValueError:
        # unpacking or int/float conversion failed
        return None
times.py 文件源码 项目:My-Web-Server-Framework-With-Python2.7 作者: syjsu 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def Time_or_None(s):
    try:
        h, m, s = s.split(':')
        h, m, s = int(h), int(m), float(s)
        return time(hour=h, minute=m, second=int(s),
                    microsecond=int(math.modf(s)[0] * 1000000))
    except ValueError:
        return None
geolite.py 文件源码 项目:editolido 作者: flyingeek 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def latlng2dm(latlng):
    """
    Degrees Minutes representation of LatLng
    :param latlng: LatLng
    :return: unicode
    >>> latlng2dm(LatLng(45.5, 30.5))
    u'N4530.0E03030.0'
    """
    def dm(v, pattern):
        f, degrees = math.modf(abs(v))
        cents, minutes = math.modf(f * 60)
        cents = round(cents * 10)
        if cents >= 10:
            cents = 0
            minutes += 1
        return pattern.format(
            int(degrees),
            int(minutes),
            int(cents)
        )

    return '{0}{1}{2}{3}'.format(
        'N' if latlng.latitude >= 0 else 'S',
        dm(latlng.latitude, '{0:0>2d}{1:0>2d}.{2}'),
        'E' if latlng.longitude > 0 else 'W',
        dm(latlng.longitude, '{0:0>3d}{1:0>2d}.{2}'),
    )
discuz_7_2_sqlinj.py 文件源码 项目:PocHunter 作者: DavexPro 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def microtime(get_as_float=False):
        if get_as_float:
            return time.time()
        else:
            return '%.8f %d' % math.modf(time.time())
discuz_7_2_sqlinj.py 文件源码 项目:PocHunter 作者: DavexPro 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def microtime(get_as_float=False):
        if get_as_float:
            return time.time()
        else:
            return '%.8f %d' % math.modf(time.time())
stocksim.py 文件源码 项目:pythonprog 作者: dabeaz 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def minutes_to_str(m):
    frac,m = math.modf(m)
    hours = m//60
    minutes = m % 60
    seconds = frac * 60
    return "%02d:%02d.%02.f" % (hours,minutes,seconds)

# Read the stock history file as a list of lists


问题


面经


文章

微信
公众号

扫码关注公众号