simon-git: spigot (master): Simon Tatham

Commits to Tartarus hosted VCS tartarus-commits at lists.tartarus.org
Sat Oct 7 21:19:18 BST 2017


TL;DR:
  fc8d4b0 Redesign the API to printf_format().
  ffde19c New printf flag to centre the string.
  f2b0ff8 New printf flag to put commas every 3 integer digits.
  ee7ee98 Add a __format__ method to the Python wrapper class.
  f50c275 Use the new __format__ in the Python demo collection.

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 21:19:18

commit fc8d4b09ffdd4fed74fb922de6d323c3bef6e9a2
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=fc8d4b09ffdd4fed74fb922de6d323c3bef6e9a2;hp=9fcca217b0e0608edf2f04633fa4b15f9b5f98e1
Author: Simon Tatham <anakin at pobox.com>
Date:   Sat Oct 7 20:50:05 2017 +0100

    Redesign the API to printf_format().
    
    Now, instead of receiving a bitmap of which standard printf flag
    characters were given in the format string, it gets the same
    information in a more cooked form, in particular separately indicating
    _where_ it should put padding for a large field width and _what_ the
    padding should be.
    
    No functional change (intended) in this commit, but this API change
    should make it easier to set the same set of input data to
    printf_format based on a different concrete format-string syntax such
    as Python's string.format system.

 baseout.cpp | 51 +++++++++++++++++++++++++++------------------------
 baseout.h   | 28 +++++++++++++++++++++++-----
 main.cpp    | 37 ++++++++++++++++++++++++++++++++-----
 3 files changed, 82 insertions(+), 34 deletions(-)

commit ffde19cf1416e70e77d7aaf8762127bd85607196
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=ffde19cf1416e70e77d7aaf8762127bd85607196;hp=fc8d4b09ffdd4fed74fb922de6d323c3bef6e9a2
Author: Simon Tatham <anakin at pobox.com>
Date:   Sat Oct 7 20:50:25 2017 +0100

    New printf flag to centre the string.
    
    This isn't enabled by any piece of actual C printf format string
    syntax, but it's a formatting mode that baseout.cpp can handle with no
    difficulty and that the Python string format syntax _will_ want to be
    able to specify.

 baseout.cpp | 16 ++++++++++++----
 baseout.h   | 11 +++++++----
 2 files changed, 19 insertions(+), 8 deletions(-)

commit f2b0ff84d10b71b46f1711d191793dbc780e3aba
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=f2b0ff84d10b71b46f1711d191793dbc780e3aba;hp=ffde19cf1416e70e77d7aaf8762127bd85607196
Author: Simon Tatham <anakin at pobox.com>
Date:   Sat Oct 7 21:08:45 2017 +0100

    New printf flag to put commas every 3 integer digits.
    
    Again, this isn't used by spigot proper's parser for C printf format
    strings, but it will be used by Python string.format syntax.

 baseout.cpp | 7 ++++++-
 baseout.h   | 1 +
 2 files changed, 7 insertions(+), 1 deletion(-)

commit ee7ee98f337f98f84dceaaf374c0532e845ce508
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=ee7ee98f337f98f84dceaaf374c0532e845ce508;hp=f2b0ff84d10b71b46f1711d191793dbc780e3aba
Author: Simon Tatham <anakin at pobox.com>
Date:   Sat Oct 7 19:56:26 2017 +0100

    Add a __format__ method to the Python wrapper class.
    
    This parses the same format strings that standard string.format syntax
    for floats supports, but instead of applying them to the result of
    converting the Spigot _to_ a float, it feeds the resulting set of
    flags and configuration to baseout.cpp and lets that do the
    printf-style formatting.
    
    The result is that you can write "{:.40}".format(spigot.pi) in just
    the same way that you might format an ordinary float, and it will just
    happen that all 40 (or 4000, if you ask for that many instead) of the
    digits you get back will actually be accurate.
    
    Unfortunately, this only applies to the new-style Python string.format
    system. The old printf-style format strings used with the % operator
    are not customisable in the same way, so writing "%.40f" % spigot.pi
    will do an implicit conversion to float and will _not_ give you 40
    true digits of pi. There's nothing I can do about that, sadly.

 python/pyspig.cpp       | 41 +++++++++++++++++++++++++-
 python/spig/__init__.py | 77 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 117 insertions(+), 1 deletion(-)

commit f50c2754417911614f5d8b902e8af9f0ca762362
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=f50c2754417911614f5d8b902e8af9f0ca762362;hp=ee7ee98f337f98f84dceaaf374c0532e845ce508
Author: Simon Tatham <anakin at pobox.com>
Date:   Sat Oct 7 19:56:33 2017 +0100

    Use the new __format__ in the Python demo collection.
    
    This wipes out all my previous ad-hoc uses of float() for quick and
    dirty conversion of Spigot objects into something I could print in
    diagnostics. There is one _new_ use of that float() idiom in test.py,
    which is there to demonstrate the difference between applying the same
    format string to a spigot and to its best float approximation.

 python/mediant.py  |  2 +-
 python/powbegin.py | 20 ++++++++++----------
 python/test.py     | 11 ++++++-----
 3 files changed, 17 insertions(+), 16 deletions(-)



More information about the tartarus-commits mailing list