Skip to content

Commit dcae1eb

Browse files
committed
Documentation fixing, TODO fixing
1 parent 4ca0c36 commit dcae1eb

File tree

5 files changed

+53
-88
lines changed

5 files changed

+53
-88
lines changed

README.rst

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,21 @@ Installing from PyPI
3535
.. note:: This library is not available on PyPI yet. Install documentation is included
3636
as a standard element. Stay tuned for PyPI availability!
3737

38-
.. todo:: Remove the above note if PyPI version is/will be available at time of release.
38+
.. Remove the above note if PyPI version is/will be available at time of release.
3939
If the library is not planned for PyPI, remove the entire 'Installing from PyPI' section.
4040
4141
On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from
42-
PyPI <https://pypi.org/project/adafruit-circuitpython-udecimal/>`_. To install for current user:
42+
PyPI <https://pypi.org/project/jepler-circuitpython-udecimal/>`_. To install for current user:
4343

4444
.. code-block:: shell
4545
46-
pip3 install adafruit-circuitpython-udecimal
46+
pip3 install jepler-circuitpython-udecimal
4747
4848
To install system-wide (this may be required in some cases):
4949

5050
.. code-block:: shell
5151
52-
sudo pip3 install adafruit-circuitpython-udecimal
52+
sudo pip3 install jepler-circuitpython-udecimal
5353
5454
To install in a virtual environment in your current project:
5555

@@ -58,12 +58,19 @@ To install in a virtual environment in your current project:
5858
mkdir project-name && cd project-name
5959
python3 -m venv .env
6060
source .env/bin/activate
61-
pip3 install adafruit-circuitpython-udecimal
61+
pip3 install jepler-circuitpython-udecimal
6262
6363
Usage Example
6464
=============
6565

66-
.. todo:: Add a quick, simple example. It and other examples should live in the examples folder and be included in docs/examples.rst.
66+
.. code-block:: python
67+
68+
>>> from jepler_udecimal import Decimal
69+
>>> Decimal(2)/3
70+
Decimal('0.6666666666666666666666666667')
71+
>>> Decimal('.1') + Decimal('.2') == Decimal('.3')
72+
True
73+
6774
6875
Contributing
6976
============

docs/examples.rst

Lines changed: 0 additions & 8 deletions
This file was deleted.

docs/index.rst

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ Table of Contents
99

1010
self
1111

12-
.. toctree::
13-
:caption: Examples
14-
15-
examples
16-
1712
.. toctree::
1813
:caption: API Reference
1914
:maxdepth: 3
@@ -23,19 +18,10 @@ Table of Contents
2318
.. toctree::
2419
:caption: Tutorials
2520

26-
.. todo:: Add any Learn guide links here. If there are none, then simply delete this todo and leave
27-
the toctree above for use later.
28-
29-
.. toctree::
30-
:caption: Related Products
31-
32-
.. todo:: Add any product links here. If there are none, then simply delete this todo and leave
33-
the toctree above for use later.
34-
3521
.. toctree::
3622
:caption: Other Links
3723

38-
Download <https://github.com/jepler/jepler_CircuitPython_udecimal/releases/latest>
24+
Download <https://github.com/jepler/Jepler_CircuitPython_udecimal/releases/latest>
3925
CircuitPython Reference Documentation <https://circuitpython.readthedocs.io>
4026
CircuitPython Support Forum <https://forums.adafruit.com/viewforum.php?f=60>
4127
Discord Chat <https://adafru.it/discord>

jepler_udecimal/__init__.py

Lines changed: 38 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@
4646
issues associated with binary floating point. The package is especially
4747
useful for financial applications or for contexts where users have
4848
expectations that are at odds with binary floating point (for instance,
49-
in binary floating point, `1.00 % 0.1` gives `0.09999999999999995` instead
50-
of `0.0`; `Decimal('1.00') % Decimal('0.1')` returns the expected
51-
`Decimal('0.00')`).
49+
in binary floating point, ``1.00 % 0.1`` gives ``0.09999999999999995`` instead
50+
of ``0.0``; ``Decimal('1.00') % Decimal('0.1')`` returns the expected
51+
``Decimal('0.00')``).
5252
5353
Here are some examples of using the udecimal module:
5454
@@ -475,6 +475,9 @@ def localcontext(ctx=None):
475475
Uses a copy of the current context if no context is specified
476476
The returned context manager creates a local decimal context
477477
in a with statement:
478+
479+
.. code-block:: python
480+
478481
def sin(x):
479482
with localcontext() as ctx:
480483
ctx.prec += 2
@@ -489,21 +492,24 @@ def sin(x):
489492
# General Decimal Arithmetic Specification
490493
return +s # Convert result to normal context
491494
492-
>>> setcontext(DefaultContext)
493-
>>> print(getcontext().prec)
494-
28
495-
>>> with localcontext():
496-
... ctx = getcontext()
497-
... ctx.prec += 2
498-
... print(ctx.prec)
499-
...
500-
30
501-
>>> with localcontext(ExtendedContext):
502-
... print(getcontext().prec)
503-
...
504-
9
505-
>>> print(getcontext().prec)
506-
28
495+
496+
.. code-block:: python
497+
498+
>>> setcontext(DefaultContext)
499+
>>> print(getcontext().prec)
500+
28
501+
>>> with localcontext():
502+
... ctx = getcontext()
503+
... ctx.prec += 2
504+
... print(ctx.prec)
505+
...
506+
30
507+
>>> with localcontext(ExtendedContext):
508+
... print(getcontext().prec)
509+
...
510+
9
511+
>>> print(getcontext().prec)
512+
28
507513
"""
508514
if ctx is None:
509515
ctx = getcontext()
@@ -689,8 +695,9 @@ def from_float(cls, f):
689695
Note that Decimal.from_float(0.1) is not the same as Decimal('0.1').
690696
Since 0.1 is not exactly representable in binary floating point, the
691697
value is stored as the nearest representable value which is
692-
0x1.999999999999ap-4. The exact equivalent of the value in decimal
693-
is 0.1000000000000000055511151231257827021181583404541015625.
698+
0x1.999999999999ap-4. The exact equivalent of the value in decimal is
699+
0.1000000000000000055511151231257827021181583404541015625 on desktop
700+
Python. On CircuitPython, the value has fewer significant figures.
694701
695702
>>> Decimal.from_float(0.1)
696703
Decimal('0.1000000000000000055511151231257827021181583404541015625')
@@ -2115,28 +2122,7 @@ def _power_exact(self, other, p):
21152122
return _dec_from_triple(0, str_xc + "0" * zeros, xe - zeros)
21162123

21172124
def __pow__(self, other, *, context=None):
2118-
"""Return self ** other [ % modulo].
2119-
2120-
With two arguments, compute self**other.
2121-
2122-
With three arguments, compute (self**other) % modulo. For the
2123-
three argument form, the following restrictions on the
2124-
arguments hold:
2125-
2126-
- all three arguments must be integral
2127-
- other must be nonnegative
2128-
- either self or other (or both) must be nonzero
2129-
- modulo must be nonzero and must have at most p digits,
2130-
where p is the context precision.
2131-
2132-
If any of these restrictions is violated the InvalidOperation
2133-
flag is raised.
2134-
2135-
The result of pow(self, other, modulo) is identical to the
2136-
result that would be obtained by computing (self**other) %
2137-
modulo with unbounded precision, but is computed more
2138-
efficiently. It is always exact.
2139-
"""
2125+
"""Return self ** other."""
21402126

21412127
other = _convert_other(other)
21422128
if other is NotImplemented:
@@ -3396,20 +3382,16 @@ def __exit__(self, t, v, tb):
33963382
class Context(object):
33973383
"""Contains the context for a Decimal instance.
33983384
3399-
Contains:
3400-
prec - precision (for use in rounding, division, square roots..)
3401-
rounding - rounding type (how you round)
3402-
traps - If traps[exception] = 1, then the exception is
3403-
raised when it is caused. Otherwise, a value is
3404-
substituted in.
3405-
flags - When an exception is caused, flags[exception] is set.
3406-
(Whether or not the trap_enabler is set)
3407-
Should be reset by user of Decimal instance.
3408-
Emin - Minimum exponent
3409-
Emax - Maximum exponent
3410-
capitals - If 1, 1*10^1 is printed as 1E+1.
3411-
If 0, printed as 1e1
3412-
clamp - If 1, change exponents if too high (Default 0)
3385+
:param int prec: precision (for use in rounding, division, square roots..)
3386+
:param str rounding: rounding type (how you round)
3387+
:param dict traps: if traps[exception] = 1, then the exception is
3388+
raised when it is caused. Otherwise, a value is
3389+
substituted in.
3390+
:param dict flags: when an exception is caused, flags[exception] is set. (Whether or not the trap_enabler is set) Should be reset by user of Decimal instance.
3391+
:param int Emin: minimum exponent
3392+
:param int Emax: maximum exponent
3393+
:param bool capitals: if true, 1*10^1 is printed as 1E+1, else printed as 1e1
3394+
:param bool clamp: If true, change exponents if too high
34133395
"""
34143396

34153397
def __init__(

setup.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,5 @@
5353
"precision math",
5454
# You can just specify the packages manually here if your project is
5555
# simple. Or you can use find_packages().
56-
# TODO: IF LIBRARY FILES ARE A PACKAGE FOLDER,
57-
# CHANGE `py_modules=['...']` TO `packages=['...']`
58-
py_modules=["jepler_udecimal"],
56+
packages=["jepler_udecimal"],
5957
)

0 commit comments

Comments
 (0)