Okay, here's the barebones, scrapped together version. It's ugly. It's messy. It might eat your kids. On the other hand, it seems to work.<br><br><a href="http://umass.glexia.net/mpf.tar.bz2">http://umass.glexia.net/mpf.tar.bz2
</a><br><br>It provides a module, mpf, with an MPF type and a bunch of methods.<br>You can directly set the value of an MPF type by setting the value attribute to a string containing a number.<br>You can read the value of an MPF type by getting value. Note that it will come back as a tuple in the form
<br>(base, sign, whole, decimal)<br><br>whole and decimal will be strings. This is to avoid losing precision. I couldn't think of another way to easily work with values that can be<br>(theoretically) infinite.<br><br>
If the number is 0, value will be None. If there isn't a whole part (or a decimal part), its place in the tuple will be set to None.<br>If you want to change the default precision (128 bits), use the keyword prec in the costructor. It takes a Long.
<br><br>The MPF type implements rich comparisons. The MPF type does not (yet) implement the Number methods. It will.<br> The methods provided by mpf are...<br><br>(these methods take two MPF values and return an MPF value):
<br><br>mpf_add<br> mpf_sub<br>mpf_div<br>mpf_mul<br><br>(these methods take one MPF value and return... gasp.. one MPF value):<br><br>mpf_sqrt<br>mpf_abs<br>mpf_neg<br><br>(this method has a stub and does not exist yet):
<br><br>mpf_pow<br><br>Sharp Edges:<br><br>If you try to set value to something weird, like a dictionary, it will segfault. PyString_Check wasn't working for me. It's in there, but defined out.<br>If you divide by zero, GNU MP will crash it saying "Floating point exception." Same goes for... well, I forgot already. I've been hacking on this nearly
<br>24 hours straight and I'm new to both the Python API and GNU MP.<br><br>Anything else? Good luck, hope someone likes it. I'll be continuing to work on it, hopefully eliminate some redundancy in the code,<br>clean it up, flesh out the floating point support. After that, it's on to integers.