1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
|
.. wxPython Phoenix documentation
This file was generated by Phoenix's sphinx generator and associated
tools, do not edit by hand.
Copyright: (c) 2011-2018 by Total Control Software
License: wxWindows License
.. include:: headings.inc
.. currentmodule:: wx.lib.agw.floatspin
.. highlight:: python
.. _wx.lib.agw.floatspin.FixedPoint:
==========================================================================================================================================
|phoenix_title| **wx.lib.agw.floatspin.FixedPoint**
==========================================================================================================================================
FixedPoint objects support decimal arithmetic with a fixed number of
digits (called the object's precision) after the decimal point. The
number of digits before the decimal point is variable & unbounded.
The precision is user-settable on a per-object basis when a FixedPoint
is constructed, and may vary across FixedPoint objects. The precision
may also be changed after construction via `FixedPoint.set_precision(p)`.
Note that if the precision of a FixedPoint is reduced via :meth:`FixedPoint.set_precision() <FixedPoint.set_precision>`,
information may be lost to rounding.
Example::
>>> x = FixedPoint("5.55") # precision defaults to 2
>>> print(x)
5.55
>>> x.set_precision(1) # round to one fraction digit
>>> print(x)
5.6
>>> print(FixedPoint("5.55", 1)) # same thing setting to 1 in constructor
5.6
>>> repr(x) # returns constructor string that reproduces object exactly
"FixedPoint('5.6', 1)"
>>>
When :class:`FixedPoint` objects of different precision are combined via + - * /,
the result is computed to the larger of the inputs' precisions, which also
becomes the precision of the resulting :class:`FixedPoint` object. Example::
>>> print FixedPoint("3.42") + FixedPoint("100.005", 3)
103.425
>>>
When a :class:`FixedPoint` is combined with other numeric types (ints, floats,
strings representing a number) via + - * /, then similarly the computation
is carried out using -- and the result inherits -- the :class:`FixedPoint`'s
precision. Example::
>>> print(FixedPoint(1) / 7)
0.14
>>> print(FixedPoint(1, 30) / 7)
0.142857142857142857142857142857
>>>
The string produced by `str(x)` (implictly invoked by `print`) always
contains at least one digit before the decimal point, followed by a
decimal point, followed by exactly `x.get_precision()` digits. If `x` is
negative, `str(x)[0] == "-"`.
The :class:`FixedPoint` constructor can be passed an int, long, string, float,
:class:`FixedPoint`, or any object convertible to a float via `float()` or to a
long via `long()`. Passing a precision is optional; if specified, the
precision must be a non-negative int. There is no inherent limit on
the size of the precision, but if very very large you'll probably run
out of memory.
Note that conversion of floats to :class:`FixedPoint` can be surprising, and
should be avoided whenever possible. Conversion from string is exact
(up to final rounding to the requested precision), so is greatly
preferred. Example::
>>> print(FixedPoint(1.1e30))
1099999999999999993725589651456.00
>>> print(FixedPoint("1.1e30"))
1100000000000000000000000000000.00
>>>
|
|class_hierarchy| Class Hierarchy
=================================
.. raw:: html
<div id="toggleBlock" onclick="return toggleVisibility(this)" class="closed" style="cursor:pointer;">
<img id="toggleBlock-trigger" src="_static/images/closed.png"/>
Inheritance diagram for class <strong>FixedPoint</strong>:
</div>
<div id="toggleBlock-summary" style="display:block;"></div>
<div id="toggleBlock-content" style="display:none;">
<p class="graphviz">
<center><img src="_static/images/inheritance/wx.lib.agw.floatspin.FixedPoint_inheritance.png" alt="Inheritance diagram of FixedPoint" usemap="#dummy" class="inheritance"/></center>
</div>
<script type="text/javascript">toggleVisibilityOnLoad(document.getElementById('toggleBlock'))</script>
<map id="dummy" name="dummy"> <area shape="rect" id="node1" href="wx.lib.agw.floatspin.FixedPoint.html" title="wx.lib.agw.floatspin.FixedPoint" alt="" coords="4,5,213,35"/> </map>
</p>
|
|method_summary| Methods Summary
================================
================================================================================ ================================================================================
:meth:`~wx.lib.agw.floatspin.FixedPoint.__init__` Default class constructor.
:meth:`~wx.lib.agw.floatspin.FixedPoint.copy` Create a copy of the current :class:`FixedPoint`.
:meth:`~wx.lib.agw.floatspin.FixedPoint.frac` Returns fractional portion as a :class:`FixedPoint`.
:meth:`~wx.lib.agw.floatspin.FixedPoint.get_precision` Return the precision of this :class:`FixedPoint`.
:meth:`~wx.lib.agw.floatspin.FixedPoint.set_precision` Change the precision carried by this :class:`FixedPoint` to `precision`.
================================================================================ ================================================================================
|
|api| Class API
===============
.. class:: FixedPoint(object)
FixedPoint objects support decimal arithmetic with a fixed number of
digits (called the object's precision) after the decimal point. The
number of digits before the decimal point is variable & unbounded.
The precision is user-settable on a per-object basis when a FixedPoint
is constructed, and may vary across FixedPoint objects. The precision
may also be changed after construction via `FixedPoint.set_precision(p)`.
Note that if the precision of a FixedPoint is reduced via :meth:`FixedPoint.set_precision() <FixedPoint.set_precision>`,
information may be lost to rounding.
Example::
>>> x = FixedPoint("5.55") # precision defaults to 2
>>> print(x)
5.55
>>> x.set_precision(1) # round to one fraction digit
>>> print(x)
5.6
>>> print(FixedPoint("5.55", 1)) # same thing setting to 1 in constructor
5.6
>>> repr(x) # returns constructor string that reproduces object exactly
"FixedPoint('5.6', 1)"
>>>
When :class:`FixedPoint` objects of different precision are combined via + - * /,
the result is computed to the larger of the inputs' precisions, which also
becomes the precision of the resulting :class:`FixedPoint` object. Example::
>>> print FixedPoint("3.42") + FixedPoint("100.005", 3)
103.425
>>>
When a :class:`FixedPoint` is combined with other numeric types (ints, floats,
strings representing a number) via + - * /, then similarly the computation
is carried out using -- and the result inherits -- the :class:`FixedPoint`'s
precision. Example::
>>> print(FixedPoint(1) / 7)
0.14
>>> print(FixedPoint(1, 30) / 7)
0.142857142857142857142857142857
>>>
The string produced by `str(x)` (implictly invoked by `print`) always
contains at least one digit before the decimal point, followed by a
decimal point, followed by exactly `x.get_precision()` digits. If `x` is
negative, `str(x)[0] == "-"`.
The :class:`FixedPoint` constructor can be passed an int, long, string, float,
:class:`FixedPoint`, or any object convertible to a float via `float()` or to a
long via `long()`. Passing a precision is optional; if specified, the
precision must be a non-negative int. There is no inherent limit on
the size of the precision, but if very very large you'll probably run
out of memory.
Note that conversion of floats to :class:`FixedPoint` can be surprising, and
should be avoided whenever possible. Conversion from string is exact
(up to final rounding to the requested precision), so is greatly
preferred. Example::
>>> print(FixedPoint(1.1e30))
1099999999999999993725589651456.00
>>> print(FixedPoint("1.1e30"))
1100000000000000000000000000000.00
>>>
.. method:: __init__(self, value=0, precision=DEFAULT_PRECISION)
Default class constructor.
:param `value`: the initial value;
:param `precision`: must be an int >= 0, and defaults to ``DEFAULT_PRECISION``.
.. method:: copy(self)
Create a copy of the current :class:`FixedPoint`.
.. method:: frac(self)
Returns fractional portion as a :class:`FixedPoint`.
:note: In :class:`FixedPoint`,
this equality holds true::
x = x.frac() + long(x)
.. method:: get_precision(self)
Return the precision of this :class:`FixedPoint`.
:note: The precision is the number of decimal digits carried after
the decimal point, and is an int >= 0.
.. method:: set_precision(self, precision=DEFAULT_PRECISION)
Change the precision carried by this :class:`FixedPoint` to `precision`.
:param `precision`: must be an int >= 0, and defaults to
``DEFAULT_PRECISION``.
:note: If `precision` is less than this :class:`FixedPoint`'s current precision,
information may be lost to rounding.
|