有理数 [英] Rational numbers

查看:86
本文介绍了有理数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我开始使用有理数,因为我发现没有包含电池,

我尝试了mxNumber包。


然而,我在比较操作上得到了奇怪的警告

(但它似乎产生了正确的结果):


---

$ python

Python 2.4.3(#1,2007年1月15日,15:46:19)

[GCC 4.1.1( Linux2上的Gentoo 4.1.1-r3)]

Hi,

I am starting to use rationals and since I found no batteries included,
I tried out the mxNumber package.

However, I get strange warnings on comparison operations
(which however seem to yield correct results):

---
$ python
Python 2.4.3 (#1, Jan 15 2007, 15:46:19)
[GCC 4.1.1 (Gentoo 4.1.1-r3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.


>>来自mx.Number import *
a = Rational( 0,1)
a
>>from mx.Number import *
a=Rational(0,1)
a



0/1

0/1


>> str(a)
>>str(a)



''0.0''

''0.0''


>> b = -5000000000000000000000000000000000000000000000000000 00000000
b
>>b=-50000000000000000000000000000000000000000000000000 00000000
b



-50000000000000000000000000000000000000000000000000 00000000L

-50000000000000000000000000000000000000000000000000 00000000L


>> a == b
>>a==b



__main __:1:RuntimeWarning:tp_compare didn不回来-1,0或1

错误

__main__:1: RuntimeWarning: tp_compare didn''t return -1, 0 or 1
False


>> ;>
>>>



---


如何摆脱这些警告?


周围是否有任何有理数的数据库

1)对于大分母而言相对较快

2)允许从Rational派生类型包裹?


问候


马丁


PS各自的邮件列表不喜欢我,所以我在这里尝试了我的

运气。

---

How do I get rid of these warnings?

Is there any rational number library around that
1) is comparably fast for large denominators
2) allows deriving types from Rationals without wrapping?

Regards

Martin

P.S. The respective mailing list does not like me, so that I try my
luck here.

推荐答案

python

Python 2.4.3(#1,2007年1月15日,15:46:19)

[GCC 4.1.1(Gentoo 4.1.1-r3)] on linux2

输入help,copyright,credit等。或许可证或欲获得更多信息。
python
Python 2.4.3 (#1, Jan 15 2007, 15:46:19)
[GCC 4.1.1 (Gentoo 4.1.1-r3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>来自mx.Number import *
a = Rational( 0,1)
a
>>from mx.Number import *
a=Rational(0,1)
a



0/1

0/1


>> str(a)
>>str(a)



''0.0''

''0.0''


>> b = -5000000000000000000000000000000000000000000000000000 00000000
b
>>b=-50000000000000000000000000000000000000000000000000 00000000
b



-50000000000000000000000000000000000000000000000000 00000000L

-50000000000000000000000000000000000000000000000000 00000000L


>> a == b
>>a==b



__main __:1:RuntimeWarning:tp_compare didn不回来-1,0或1

错误

__main__:1: RuntimeWarning: tp_compare didn''t return -1, 0 or 1
False


>> ;>
>>>



---


如何摆脱这些警告?


周围是否有任何有理数的数据库

1)对于大分母而言相对较快

2)允许从Rational派生类型包裹?


问候


马丁


PS各自的邮件列表不喜欢我,所以我在这里尝试了我的

运气。

---

How do I get rid of these warnings?

Is there any rational number library around that
1) is comparably fast for large denominators
2) allows deriving types from Rationals without wrapping?

Regards

Martin

P.S. The respective mailing list does not like me, so that I try my
luck here.


Martin Manns写道:
Martin Manns wrote:




我开始使用有理数,因为我发现没有包含电池,

我尝试了mxNumber包。


然而,我在比较操作上收到奇怪的警告

(但这似乎产生了正确的结果):


---
Hi,

I am starting to use rationals and since I found no batteries included,
I tried out the mxNumber package.

However, I get strange warnings on comparison operations
(which however seem to yield correct results):

---


python

Python 2.4.3(#1,2007年1月15日,15:46:19)< br>
[gCC 4.1.1(Gentoo 4.1.1-r3)] on linux2

输入help,copyright,credit等等。或许可证或欲获得更多信息。
python
Python 2.4.3 (#1, Jan 15 2007, 15:46:19)
[GCC 4.1.1 (Gentoo 4.1.1-r3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>>来自mx.Number import *
a = Rational(0,1)
a
>>>from mx.Number import *
a=Rational(0,1)
a



0/1

0/1


>>> str(a)
>>>str(a)



''0.0''

''0.0''


>>> b = -50000000000000000000000000000000000000000000000000 00000000
b
>>>b=-50000000000000000000000000000000000000000000000000 00000000
b



-50000000000000000000000000000000000000000000000000 00000000L

-50000000000000000000000000000000000000000000000000 00000000L


>>> a == b
>>>a==b



__main __:1:运行时警告:tp_compare没有返回-1,0或1

错误

---


如何摆脱这些警告?


周围是否有合理的数字库

1)相对较快的大分母

2)允许从Rationals派生类型而不包装?


问候


马丁


PS各自的邮件列表不喜欢我,所以我在这里尝试了我的

运气。

__main__:1: RuntimeWarning: tp_compare didn''t return -1, 0 or 1
False
---

How do I get rid of these warnings?

Is there any rational number library around that
1) is comparably fast for large denominators
2) allows deriving types from Rationals without wrapping?

Regards

Martin

P.S. The respective mailing list does not like me, so that I try my
luck here.



我快速搜索Google了:

http:// books。 google.com/books?id=1Sh...PSweVNyi8cS2eg
http://calcrpnpy.sourceforge.net/clnum.html
http ://gmpy.sourceforge.net/


-Larry

I quick search of Google turned up:

http://books.google.com/books?id=1Sh...PSweVNyi8cS2eg
http://calcrpnpy.sourceforge.net/clnum.html
http://gmpy.sourceforge.net/

-Larry


这篇关于有理数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆