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


Python types.FloatType方法代码示例

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


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

示例1: assertEquals

# 需要导入模块: import types [as 别名]
# 或者: from types import FloatType [as 别名]
def assertEquals( exp, got ):
        """assertEquals(exp, got)

        Two objects test as "equal" if:
        
        * they are the same object as tested by the 'is' operator.
        * either object is a float or complex number and the absolute
          value of the difference between the two is less than 1e-8.
        * applying the equals operator ('==') returns True.
        """
        from types import FloatType, ComplexType
        if exp is got:
            r = True
        elif ( type( exp ) in ( FloatType, ComplexType ) or
               type( got ) in ( FloatType, ComplexType ) ):
            r = abs( exp - got ) < 1e-8
        else:
            r = ( exp == got )
        if not r:
            print >>sys.stderr, "Error: expected <%s> but got <%s>" % ( repr( exp ), repr( got ) )
            traceback.print_stack() 
开发者ID:ActiveState,项目名称:code,代码行数:23,代码来源:recipe-577473.py

示例2: assertEquals

# 需要导入模块: import types [as 别名]
# 或者: from types import FloatType [as 别名]
def assertEquals( exp, got, msg = None ):
    """assertEquals( exp, got[, message] )

    Two objects test as "equal" if:
    
    * they are the same object as tested by the 'is' operator.
    * either object is a float or complex number and the absolute
      value of the difference between the two is less than 1e-8.
    * applying the equals operator ('==') returns True.
    """
    if exp is got:
        r = True
    elif ( type( exp ) in ( FloatType, ComplexType ) or
           type( got ) in ( FloatType, ComplexType ) ):
        r = abs( exp - got ) < 1e-8
    else:
        r = ( exp == got )
    if not r:
        print >>sys.stderr, "Error: expected <%s> but got <%s>%s" % ( repr( exp ), repr( got ), colon( msg ) )
        traceback.print_stack() 
开发者ID:ActiveState,项目名称:code,代码行数:22,代码来源:recipe-577538.py

示例3: assertNotEquals

# 需要导入模块: import types [as 别名]
# 或者: from types import FloatType [as 别名]
def assertNotEquals( exp, got, msg = None ):
    """assertNotEquals( exp, got[, message] )

    Two objects test as "equal" if:
    
    * they are the same object as tested by the 'is' operator.
    * either object is a float or complex number and the absolute
      value of the difference between the two is less than 1e-8.
    * applying the equals operator ('==') returns True.
    """
    if exp is got:
        r = False
    elif ( type( exp ) in ( FloatType, ComplexType ) or
           type( got ) in ( FloatType, ComplexType ) ):
        r = abs( exp - got ) >= 1e-8
    else:
        r = ( exp != got )
    if not r:
        print >>sys.stderr, "Error: expected different values but both are equal to <%s>%s" % ( repr( exp ), colon( msg ) )
        traceback.print_stack() 
开发者ID:ActiveState,项目名称:code,代码行数:22,代码来源:recipe-577538.py

示例4: realEncode

# 需要导入模块: import types [as 别名]
# 或者: from types import FloatType [as 别名]
def realEncode(self, data):
        """Convert number to string.
        If no formatString was specified in class constructor data type is
        dynamically determined and converted using a default formatString of
        "%d", "%f", or "%d" for Int, Float, and Long respectively.
        """

        if self._formatString is None:
            retType = type(data)
            if retType is IntType:
                return "%d" % data
            elif retType is FloatType:
                return "%f" % data
            elif retType is LongType:
                return "%d" % data
            else:
                return data

        return self._formatString % data 
开发者ID:MozillaSecurity,项目名称:peach,代码行数:21,代码来源:NumberToString.py

示例5: radius

# 需要导入模块: import types [as 别名]
# 或者: from types import FloatType [as 别名]
def radius(self, z):
        '''
        sets the height of the point constraining the plate, returns
        the radius at this point
        '''
        if isinstance(z, types.FloatType):
            self.pnt.SetX(z)
        else:
            self.pnt.SetX(float(z[0]))
        self.build_surface()
        uv = uv_from_projected_point_on_face(self.plate, self.pnt)
        print(uv)
        radius = radius_at_uv(self.plate, uv.X(), uv.Y())
        print('z: %f radius: %f ' % (z, radius))
        self.curr_radius = radius
        return self.targetRadius-abs(radius) 
开发者ID:tpaviot,项目名称:pythonocc-utils,代码行数:18,代码来源:occutils_geomplate.py

示例6: init_info

# 需要导入模块: import types [as 别名]
# 或者: from types import FloatType [as 别名]
def init_info(self):
        scalar_converter.init_info(self)
        # Not sure this is really that safe...
        self.type_name = 'float'
        self.check_func = 'PyFloat_Check'
        self.c_type = 'double'
        self.return_type = 'double'
        self.to_c_return = "PyFloat_AsDouble(py_obj)"
        self.matching_types = [types.FloatType] 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:11,代码来源:c_spec.py

示例7: mysql_escape

# 需要导入模块: import types [as 别名]
# 或者: from types import FloatType [as 别名]
def mysql_escape(f):
    @wraps(f)
    def decorated_function(*args, **kwargs):
        newargs = []
        #先转义参数,再执行方法
        for arg in args:
            #字符串,包括中文
            if type(arg) is types.StringType or type(arg) is types.UnicodeType:
                newargs.append(MySQLdb.escape_string(arg))
            
            #字典    
            elif isinstance(arg, dict):
                newargs.append(MySQLdb.escape_dict(arg, {
                                                         types.StringType: _str_escape,
                                                         types.UnicodeType: _str_escape,
                                                         types.IntType: _no_escape,
                                                         types.FloatType: _no_escape
                                                         }))
            #其他类型不转义
            else:
                newargs.append(arg)
                
        newargs = tuple(newargs)
        
        func = f(*newargs, **kwargs)
        
        return func
    return decorated_function 
开发者ID:NetEaseGame,项目名称:iOS-private-api-checker,代码行数:30,代码来源:mysql_escape_warp.py

示例8: to_sec

# 需要导入模块: import types [as 别名]
# 或者: from types import FloatType [as 别名]
def to_sec(v):
    """
    Convert millisecond, microsecond or nanosecond to second.

    ms_to_ts, us_to_ts, ns_to_ts are then deprecated.
    """

    v = float(str(v))

    if (type(v) != types.FloatType
            or v < 0):
        raise ValueError('invalid time to convert to second: {v}'.format(v=v))

    l = len(str(int(v)))

    if l == 10:
        return int(v)
    elif l == 13:
        return int(v / 1000)
    elif l == 16:
        return int(v / (1000**2))
    elif l == 19:
        return int(v / (1000**3))
    else:
        raise ValueError(
            'invalid time length, not 10, 13, 16 or 19: {v}'.format(v=v)) 
开发者ID:bsc-s2,项目名称:pykit,代码行数:28,代码来源:timeutil.py

示例9: valueTreeToString

# 需要导入模块: import types [as 别名]
# 或者: from types import FloatType [as 别名]
def valueTreeToString(fout, value, path = '.'):
    ty = type(value) 
    if ty  is types.DictType:
        fout.write('%s={}\n' % path)
        suffix = path[-1] != '.' and '.' or ''
        names = value.keys()
        names.sort()
        for name in names:
            valueTreeToString(fout, value[name], path + suffix + name)
    elif ty is types.ListType:
        fout.write('%s=[]\n' % path)
        for index, childValue in zip(xrange(0,len(value)), value):
            valueTreeToString(fout, childValue, path + '[%d]' % index)
    elif ty is types.StringType:
        fout.write('%s="%s"\n' % (path,value))
    elif ty is types.IntType:
        fout.write('%s=%d\n' % (path,value))
    elif ty is types.FloatType:
        fout.write('%s=%.16g\n' % (path,value))
    elif value is True:
        fout.write('%s=true\n' % path)
    elif value is False:
        fout.write('%s=false\n' % path)
    elif value is None:
        fout.write('%s=null\n' % path)
    else:
        assert False and "Unexpected value type" 
开发者ID:KhronosGroup,项目名称:OpenXR-SDK-Source,代码行数:29,代码来源:pyjsontestrunner.py

示例10: set_hp

# 需要导入模块: import types [as 别名]
# 或者: from types import FloatType [as 别名]
def set_hp(self, hp):
            if type(hp) in [types.IntType, types.FloatType]:
                self.__hp = hp
            else:
                self.__hp = 0 
开发者ID:PiratesOnlineRewritten,项目名称:Pirates-Online-Rewritten,代码行数:7,代码来源:DistributedCapturePoint.py

示例11: set_maxHp

# 需要导入模块: import types [as 别名]
# 或者: from types import FloatType [as 别名]
def set_maxHp(self, maxHp):
            if type(maxHp) in [types.IntType, types.FloatType]:
                self.__maxHp = maxHp
            else:
                self.__maxHp = 1 
开发者ID:PiratesOnlineRewritten,项目名称:Pirates-Online-Rewritten,代码行数:7,代码来源:DistributedCapturePoint.py

示例12: set_hp

# 需要导入模块: import types [as 别名]
# 或者: from types import FloatType [as 别名]
def set_hp(self, hp):
            if type(hp) in [types.IntType, types.FloatType]:
                self.__hp = hp
            else:
                self.__hp = 1 
开发者ID:PiratesOnlineRewritten,项目名称:Pirates-Online-Rewritten,代码行数:7,代码来源:DistributedInteractiveProp.py

示例13: __init__

# 需要导入模块: import types [as 别名]
# 或者: from types import FloatType [as 别名]
def __init__(self, name, host='ip-address', port=9955):

        Instrument.__init__(self, name, tags=['physical'])
        
        self.add_parameter('condenser_pressure',
            type=types.FloatType,
            flags=Instrument.FLAG_GET, units='mbar')
        self.add_parameter('still_pressure',
            type=types.FloatType,
            flags=Instrument.FLAG_GET, units='mbar')
            
        self.HOST, self.PORT = host, port 
开发者ID:qkitgroup,项目名称:qkit,代码行数:14,代码来源:EdwardsActiveDigitalController.py

示例14: parinfo

# 需要导入模块: import types [as 别名]
# 或者: from types import FloatType [as 别名]
def parinfo(self, parinfo=None, key='a', default=None, n=0):
		if self.debug:
			print 'Entering parinfo...'
		if (n == 0) and (parinfo is not None):
			n = len(parinfo)
		if n == 0:
			values = default
	
			return values
		values = []
		for i in range(n):
			if (parinfo is not None) and (parinfo[i].has_key(key)):
				values.append(parinfo[i][key])
			else:
				values.append(default)

		# Convert to numeric arrays if possible
		test = default
		if type(default) == types.ListType:
			test=default[0]
		if isinstance(test, types.IntType):
			values = numpy.asarray(values, int)
		elif isinstance(test, types.FloatType):
			values = numpy.asarray(values, float)
		return values
	
	# Call user function or procedure, with _EXTRA or not, with
	# derivatives or not. 
开发者ID:mzechmeister,项目名称:serval,代码行数:30,代码来源:mpfit.py

示例15: _convert_to

# 需要导入模块: import types [as 别名]
# 或者: from types import FloatType [as 别名]
def _convert_to(l, dest_unit="m"):
    if type(l) in (types.IntType, types.LongType, types.FloatType):
        return l * _m[_default_unit] * scale['u'] / _m[dest_unit]
    elif not isinstance(l, length): 
        l = length(l)       # convert to length instance if necessary

    return (l.t + l.u*scale['u'] + l.v*scale['v'] + l.w*scale['w'] + l.x*scale['x']) / _m[dest_unit] 
开发者ID:VLSIDA,项目名称:OpenRAM,代码行数:9,代码来源:unit.py


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