English 中文(简体)
p语中较快的分数模块
原标题:faster fractions module in python

<代码>fractions模块,如<编码>cFractions模块,如有<代码>cDecimal模块,该模块与<代码>Decimal模块更为对应? <代码>fractions 模块过于缓慢。

问题回答

http://code.google.com/p/gmpy/“rel=“nofollow”http://code.google.com/p/gmpy/

它利用GMP mutliple-precision图书馆进行快速编造和理算。

注:Im也是维护者。

不幸的是,在不需要经过汇编的外部依赖的情况下,没有类似的条件。 根据你们的需要,我做了以下工作:。 可能提供帮助。

它暴露了以下功能:opFrac(num),即选择性地将某一吨、浮标或Fraction转换为具有排位限制的浮标或Fraction(因为我使用65535号,因为Im与小分数做生意);如果该浮标能够确切地在双位(即它拥有两个排位数的多种力量),则只剩下。 否则,它就将它变为“框架”。 同样,如果《框架》在双程中确实具有代表性,那么我们就把它变成了浮标;否则,我们就离开了。

The actionFr(float).limit_denominator(x) calls is derived out into a helper function, _preFracLimitDenominator, that only establishs one Fr> Object, but not the three average established with the calls.

The use cases for this gist are pretty few, but where they exist, the results are spectacular. For my project, music21, we work mostly with notes that are generally placed on a beat (integer) or on a half, quarter, eighth, etc. beat (exactly representable in binary), but on the rarer occasions when notes have placement (offset) or duration that is, say, 1/3 or 1/5 of a beat, we were running into big floating point conversion problems that led to obscure bugs. Our test suite was running in 350 seconds using floating point offsets and durations. Switching everything to Fractions ballooned the time to 1100 seconds -- totally unacceptable. Switching to optional Fractions with fast Fraction creation brought the time back to 360 seconds, or only a 3% performance hit.

如果你有时能够处理浮标问题,有时甚至处理不成体系问题,那可能是前进的道路。

I couldn t find anything. You could make one.http://docs.python.org/extending/extending.html

http://www.spiration.co.uk 利用2个员额,还处理负数。

But that may not be what you need and you can find something else. If you don t want to extend python you have to stick to Fractions if you can t find anyone who has a cFractions module. I m sorry.





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签