无限的表现 [英] Rappresenting infinite
问题描述
我想有一个有用的无限代表,有没有
已经有了什么?
我是想到这样的事情
class Inf(int):
""" numero infinito"""
def __init __(self,negative = False):
self.negative = negative
def __cmp __(self,y):
" ;"" infinito maggiore di qualasiasi cosa""
if self.negative:
return -1
else:
返回1
def __repr __(自我):
""" docstring for __repr __"""
if self.negative:
返回''-inf''
否则:
返回''inf''
def __add __(self,y):
""" addizione con infinito""
返回自我
def __mul __(self,y):
""" moltiplicazione"""
i mport类型
if isinstance(y,types.IntType):
如果y 0:
返回自我
如果y == 0:
返回''indefinito''
否则:
返回Inf(负数)
我希望能够比较任何值和无限值
得到正确的结果,并注意特殊情况
喜欢
inf / inf =不确定
6月27日上午6:41,andrea< kerny .. 。@ gmail.comwrote:
我想有一个有用的无限的rappresentation,有没有
已经有了什么?
来自numpy import inf
2007年6月27日星期三11:59:29 -0000
Rob De Almeida< ra ****** @ gmail.comwrote:
6月27日,6:41 am,andrea< kerny ... @ gmail.comwrote:
我想有一个有用的无限代表,有没有
已经有了什么?
来自numpy import inf
python
Python 2.4 。4(#2,2007年4月5日,20:11:18)
[GCC 4.1.2 20061115(预发布)(Debian 4.1.1-21)]关于linux2
输入help,copyright,credit等。或许可证或欲获得更多信息。
>>来自numpy import inf
inf == inf
True
>> type(inf)
< type''flora''>
这看起来像是我的浮点信息。它与
内置inf有什么不同吗?
如果有通用inf和
添加不等于自身的愿望(inf == inf会产生
nan)。理想情况下,它不会是float类型并使用gmpy mpq。
但我可能有罕见的要求...
Martin
I would like to have a useful rappresentation of infinite, is there
already something??
I was thinking to something like this
class Inf(int):
"""numero infinito"""
def __init__(self,negative=False):
self.negative = negative
def __cmp__(self,y):
"""infinito maggiore di qualasiasi cosa"""
if self.negative:
return -1
else:
return 1
def __repr__(self):
"""docstring for __repr__"""
if self.negative:
return ''-inf''
else:
return ''inf''
def __add__(self,y):
"""addizione con infinito"""
return self
def __mul__(self,y):
"""moltiplicazione"""
import types
if isinstance(y,types.IntType):
if y 0:
return self
if y == 0:
return ''indefinito''
else:
return Inf(negative)
I''d like to be able to compare between any value and infinite always
getting the right result, and paying attention to the special cases
like
inf / inf =not determinate
On Jun 27, 6:41 am, andrea <kerny...@gmail.comwrote:I would like to have a useful rappresentation of infinite, is there
already something??from numpy import inf
On Wed, 27 Jun 2007 11:59:29 -0000
Rob De Almeida <ra******@gmail.comwrote:
On Jun 27, 6:41 am, andrea <kerny...@gmail.comwrote:I would like to have a useful rappresentation of infinite, is there
already something??
from numpy import inf
python
Python 2.4.4 (#2, Apr 5 2007, 20:11:18)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.>>from numpy import inf
inf == inf
True
>>type(inf)
<type ''float''>
This looks like the floating point inf to me. Does it differ from the
built-in inf?
I would like to second the OP''s question if there is a generic inf and
add the wish that that is not equal to itself (inf == inf would yield
nan). Ideally, it would not be of type float and work with gmpy mpq.
But I might have rare requirements...
Martin
这篇关于无限的表现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!