當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。