simon-git: spigot (master): Simon Tatham
Commits to Tartarus hosted VCS
tartarus-commits at lists.tartarus.org
Sat Oct 7 23:13:40 BST 2017
TL;DR:
d0141d4 Reorganise the Spigot class constructor.
86e8865 Add custom str() and repr() handling in class Spigot.
3fdca2d Automatic conversion from the 'fractions' module.
8e7f4db Interoperation with exact rational classes.
Repository: https://git.tartarus.org/simon/spigot.git
On the web: https://git.tartarus.org/?p=simon/spigot.git
Branch updated: master
Committer: Simon Tatham <anakin at pobox.com>
Date: 2017-10-07 23:13:40
commit d0141d4be11113720d301459b0d39083734d370b
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=d0141d4be11113720d301459b0d39083734d370b;hp=f50c2754417911614f5d8b902e8af9f0ca762362
Author: Simon Tatham <anakin at pobox.com>
Date: Sat Oct 7 22:49:17 2017 +0100
Reorganise the Spigot class constructor.
Now, you can implicitly make a spigot.Spigot() out of anything _other_
than a string containing a mathematical expression: an integer, a
float, or another spigot object (internal or wrapper). The
string-parsing and scope-handling has moved out into the separate
function spigot.eval(), which seemed like a more appropriate name to
use for arbitrary expression evaluation.
python/mediant.py | 17 +++++++++--------
python/powbegin.py | 41 ++++++++++++++++++++---------------------
python/pythangle.py | 7 +++----
python/spig/__init__.py | 46 +++++++++++++++++++++++++++-------------------
python/test.py | 9 ++++-----
5 files changed, 63 insertions(+), 57 deletions(-)
commit 86e8865ff8b94837581a3b185c013bf2d5cf1092
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=86e8865ff8b94837581a3b185c013bf2d5cf1092;hp=d0141d4be11113720d301459b0d39083734d370b
Author: Simon Tatham <anakin at pobox.com>
Date: Sat Oct 7 22:52:16 2017 +0100
Add custom str() and repr() handling in class Spigot.
str(spig) produces the same output as "{}".format(spig), which seems
appropriate. repr(spig) keeps the <...> syntax that most class types
use to indicate that they're something special, but inside that, it
will display the exact integer or rational value of a spigot if it's
got one, and failing that, do the same default str() formatting again.
So you can at least have some idea of what number your spigot
represents.
python/spig/__init__.py | 14 ++++++++++++++
1 file changed, 14 insertions(+)
commit 3fdca2d1256538952c1d7f559203835fc575a742
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=3fdca2d1256538952c1d7f559203835fc575a742;hp=86e8865ff8b94837581a3b185c013bf2d5cf1092
Author: Simon Tatham <anakin at pobox.com>
Date: Sat Oct 7 22:55:56 2017 +0100
Automatic conversion from the 'fractions' module.
If you're interested in arithmetic without errors, you may well be
using the standard library module 'fractions' already. And if you
suddenly need spigot-level computation on some number q in that
format, it would be nice if you could say Spigot(q) the same way you
would with an int or a float. Well, now you can.
python/spig/__init__.py | 3 +++
1 file changed, 3 insertions(+)
commit 8e7f4dbccef78ce1cf76a8803e05d93446f2ff29
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=8e7f4dbccef78ce1cf76a8803e05d93446f2ff29;hp=3fdca2d1256538952c1d7f559203835fc575a742
Author: Simon Tatham <anakin at pobox.com>
Date: Sat Oct 7 23:05:50 2017 +0100
Interoperation with exact rational classes.
Conversions to the Spigot class will now give the exactly right answer
if given an input object which is an instance of fractions.Fraction,
or indeed of any other class that implements the numbers.Rational
abstract base class.
Conversely, the spigot API functions that _return_ a numerator and
denominator, such as Spigot.known_rational_value() and the values
yielded from Spigot.convergents(), can now return them in the form of
a fractions class of your choice instead of a tuple of integers. But
you have to tell it to - you pass in your fractions class of choice
and it will construct things of that class. For example, you might say
'pi_iter = spigot.pi.convergents(fractions.Fraction)', and then you
have a generator that will yield you instances of Fraction; or you
could use some other equivalent class if you prefer, or pass no
argument to convergents() and still get plain (num,denom) tuples.
python/spig/__init__.py | 31 ++++++++++++++++++++-----------
1 file changed, 20 insertions(+), 11 deletions(-)
More information about the tartarus-commits
mailing list