[Python-checkins] python/dist/src/Doc/lib libdecimal.tex,1.7,1.8
rhettinger at users.sourceforge.net
rhettinger at users.sourceforge.net
Thu Jul 8 11:22:36 CEST 2004
Update of /cvsroot/python/python/dist/src/Doc/lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9905
Modified Files:
libdecimal.tex
Log Message:
Fix markup, typos, and nits.
Index: libdecimal.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/lib/libdecimal.tex,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** libdecimal.tex 6 Jul 2004 01:55:14 -0000 1.7
--- libdecimal.tex 8 Jul 2004 09:22:33 -0000 1.8
***************
*** 99,103 ****
\seetext{IEEE standard 854-1987,
! \citetitle[http://www.cs.berkeley.edu/~ejr/projects/754/private/drafts/854-1987/dir.html]
{Unofficial IEEE 854 Text}.}
\end{seealso}
--- 99,103 ----
\seetext{IEEE standard 854-1987,
! \citetitle[http://www.cs.berkeley.edu/\textasciitilde ejr/projects/754/private/drafts/854-1987/dir.html]
{Unofficial IEEE 854 Text}.}
\end{seealso}
***************
*** 121,142 ****
\end{verbatim}
! Decimal instances can be constructed from integers or strings. To create a
! Decimal from a \class{float}, first convert it to a string. This serves as an
! explicit reminder of the details of the conversion (including representation
! error). Malformed strings signal \constant{ConversionSyntax} and return a
! special kind of Decimal called a \constant{NaN} which stands for ``Not a
! number''. Positive and negative \constant{Infinity} is yet another special
! kind of Decimal.
\begin{verbatim}
>>> Decimal(10)
Decimal("10")
! >>> Decimal('3.14')
Decimal("3.14")
>>> Decimal(str(2.0 ** 0.5))
Decimal("1.41421356237")
! >>> Decimal('Mickey Mouse')
Decimal("NaN")
! >>> Decimal('-Infinity')
Decimal("-Infinity")
\end{verbatim}
--- 121,144 ----
\end{verbatim}
! Decimal instances can be constructed from integers, strings or tuples. To
! create a Decimal from a \class{float}, first convert it to a string. This
! serves as an explicit reminder of the details of the conversion (including
! representation error). Malformed strings signal \constant{ConversionSyntax}
! and return a special kind of Decimal called a \constant{NaN} which stands for
! ``Not a number''. Positive and negative \constant{Infinity} is yet another
! special kind of Decimal.
\begin{verbatim}
>>> Decimal(10)
Decimal("10")
! >>> Decimal("3.14")
! Decimal("3.14")
! >>> Decimal((0, (3, 1, 4), -2))
Decimal("3.14")
>>> Decimal(str(2.0 ** 0.5))
Decimal("1.41421356237")
! >>> Decimal("NaN")
Decimal("NaN")
! >>> Decimal("-Infinity")
Decimal("-Infinity")
\end{verbatim}
***************
*** 234,238 ****
\begin{verbatim}
>>> setcontext(ExtendedContext)
- >>> getcontext().clear_flags()
>>> Decimal(355) / Decimal(113)
Decimal("3.14159292")
--- 236,239 ----
***************
*** 315,322 ****
a \class{tuple} of digits, and an exponent represented as an integer.
For example, \samp{Decimal((0, (1, 4, 1, 4), -3))} returns
! \samp{Decimal("1.414")}.
The supplied \var{context} or, if not specified, the current context
! governs only the handling of mal-formed strings not conforming to the
numeric string syntax. If the context traps \constant{ConversionSyntax},
an exception is raised; otherwise, the constructor returns a new Decimal
--- 316,323 ----
a \class{tuple} of digits, and an exponent represented as an integer.
For example, \samp{Decimal((0, (1, 4, 1, 4), -3))} returns
! \code{Decimal("1.414")}.
The supplied \var{context} or, if not specified, the current context
! governs only the handling of malformed strings not conforming to the
numeric string syntax. If the context traps \constant{ConversionSyntax},
an exception is raised; otherwise, the constructor returns a new Decimal
***************
*** 324,328 ****
The context serves no other purpose. The number of significant digits
! recorded is determined solely by the \var{value} and the var{context}
precision is not a factor. For example, \samp{Decimal("3.0000")} records
all four zeroes even if the context precision is only three.
--- 325,329 ----
The context serves no other purpose. The number of significant digits
! recorded is determined solely by the \var{value} and the \var{context}
precision is not a factor. For example, \samp{Decimal("3.0000")} records
all four zeroes even if the context precision is only three.
***************
*** 342,349 ****
\begin{methoddesc}{adjusted}{}
! Return the number's adjusted exponent that results from shifting out the
! coefficients rightmost digits until only the lead digit remains:
! \code{Decimal("321e+5").adjusted()} returns seven. Used for determining
! the place value of the most significant digit.
\end{methoddesc}
--- 343,350 ----
\begin{methoddesc}{adjusted}{}
! Return the adjusted exponent after shifting out the coefficient's rightmost
! digits until only the lead digit remains: \code{Decimal("321e+5").adjusted()}
! returns seven. Used for determining the place value of the most significant
! digit.
\end{methoddesc}
***************
*** 374,382 ****
\begin{methoddesc}{normalize}{\optional{context}}
! Normalize the number by striping the rightmost trailing zeroes and
! converting any result equal to \constant{Decimal("0")} to Decimal("0e0").
! Used for producing a canonical value for members of an equivalence class.
! For example, \code{Decimal("32.100")} and \code{Decimal("0.321000e+2")}
! both normalize to the equivalent value \code{Decimal("32.1")}
\end{methoddesc}
--- 375,384 ----
\begin{methoddesc}{normalize}{\optional{context}}
! Normalize the number by stripping the rightmost trailing zeroes and
! converting any result equal to \constant{Decimal("0")} to
! \constant{Decimal("0e0")}. Used for producing canonical values for members
! of an equivalence class. For example, \code{Decimal("32.100")} and
! \code{Decimal("0.321000e+2")} both normalize to the equivalent value
! \code{Decimal("32.1")},
\end{methoddesc}
***************
*** 387,391 ****
in the current context.
! Of \var{watchexp} is set (default), then an error is returned if
the resulting exponent is greater than \member{Emax} or less than
\member{Etiny}.
--- 389,393 ----
in the current context.
! If \var{watchexp} is set (default), then an error is returned whenever
the resulting exponent is greater than \member{Emax} or less than
\member{Etiny}.
***************
*** 402,406 ****
\end{methoddesc}
! \begin{methoddesc}{same_quantum{other\optional{, context}}}
Test whether self and other have the same exponent or whether both
are \constant{NaN}.
--- 404,408 ----
\end{methoddesc}
! \begin{methoddesc}{same_quantum}{other\optional{, context}}
Test whether self and other have the same exponent or whether both
are \constant{NaN}.
***************
*** 412,416 ****
\begin{methoddesc}{to_eng_string}{\optional{context}}
! Convert to engineering-type string.
Engineering notation has an exponent which is a multiple of 3, so there
--- 414,418 ----
\begin{methoddesc}{to_eng_string}{\optional{context}}
! Convert to an engineering-type string.
Engineering notation has an exponent which is a multiple of 3, so there
***************
*** 420,424 ****
\begin{methoddesc}{to_integral}{\optional{rounding\optional{, context}}}
! Rounds to the nearest integer, without signaling \constant{Inexact}
or \constant{Rounded}. If given, applies \var{rounding}; otherwise,
uses the rounding method in either the supplied \var{context} or the
--- 422,426 ----
\begin{methoddesc}{to_integral}{\optional{rounding\optional{, context}}}
! Rounds to the nearest integer without signaling \constant{Inexact}
or \constant{Rounded}. If given, applies \var{rounding}; otherwise,
uses the rounding method in either the supplied \var{context} or the
***************
*** 464,467 ****
--- 466,474 ----
\constant{ROUND_HALF_EVEN}. All flags are cleared. No traps are enabled
(so that exceptions are not raised during computations).
+
+ Because the trapped are disabled, this context is useful for applications
+ that prefer to have result value of \constant{NaN} or \constant{Infinity}
+ instead of raising exceptions. This allows an application to complete a
+ run in the presense of conditions that would otherwise halt the program.
\end{classdesc*}
***************
*** 483,487 ****
cleared flags, and no traps enabled).
\end{classdesc*}
!
\begin{classdesc}{Context}{prec=None, rounding=None, trap_enablers=None,
--- 490,497 ----
cleared flags, and no traps enabled).
\end{classdesc*}
!
!
! In addition to the three supplied contexts, new contexts can be created
! with the \class{Context} constructor.
\begin{classdesc}{Context}{prec=None, rounding=None, trap_enablers=None,
***************
*** 492,502 ****
cleared.
! The \var{prec} field in an positive integer that sets the precision for
arithmetic operations in the context.
The \var{rounding} option is one of: \constant{ROUND_CEILING},
! \constant{ROUND_DOWN}, \constant{ROUND_FLOOR}, \constant{ROUND_HALF_DOWN},
! \constant{ROUND_HALF_EVEN}, \constant{ROUND_HALF_UP}, or
! \constant{ROUND_UP}.
The \var{trap_enablers} and \var{flags} fields are mappings from signals
--- 502,512 ----
cleared.
! The \var{prec} field is a positive integer that sets the precision for
arithmetic operations in the context.
The \var{rounding} option is one of: \constant{ROUND_CEILING},
! \constant{ROUND_DOWN}, \constant{ROUND_FLOOR}, \constant{ROUND_HALF_DOWN}
! (towards zero), \constant{ROUND_HALF_EVEN}, \constant{ROUND_HALF_UP}, or
! \constant{ROUND_UP} (away from zero).
The \var{trap_enablers} and \var{flags} fields are mappings from signals
***************
*** 537,549 ****
\end{methoddesc}
! The usual approach to working with decimals is to create Decimal
! instances and then apply arithmetic operations which take place
! within the current context for the active thread. An alternate
! approach is to use a context method to perform a particular
! computation within the given context rather than the current context.
- Those methods parallel those for the \class{Decimal} class and are
- only briefed recounted here.
\begin{methoddesc}{abs}{x}
--- 547,561 ----
\end{methoddesc}
! \begin{methoddesc}{Etop}{}
! Returns a value equal to \samp{Emax - prec + 1}.
! \end{methoddesc}
+ The usual approach to working with decimals is to create \class{Decimal}
+ instances and then apply arithmetic operations which take place within the
+ current context for the active thread. An alternate approach is to use
+ context methods for calculating within s specific context. The methods are
+ similar to those for the \class{Decimal} class and are only briefly recounted
+ here.
\begin{methoddesc}{abs}{x}
***************
*** 571,575 ****
\end{methoddesc}
! \begin{methoddesc}{divide}{x, y}
Divides two numbers and returns the integer part of the result.
\end{methoddesc}
--- 583,587 ----
\end{methoddesc}
! \begin{methoddesc}{divmod}{x, y}
Divides two numbers and returns the integer part of the result.
\end{methoddesc}
***************
*** 590,594 ****
\begin{methoddesc}{minus}{x}
! Minus corresponds to unary prefix minus in Python.
\end{methoddesc}
--- 602,606 ----
\begin{methoddesc}{minus}{x}
! Minus corresponds to the unary prefix minus operator in Python.
\end{methoddesc}
***************
*** 605,609 ****
\begin{methoddesc}{plus}{x}
! Minus corresponds to unary prefix plus in Python.
\end{methoddesc}
--- 617,621 ----
\begin{methoddesc}{plus}{x}
! Minus corresponds to the unary prefix plus operator in Python.
\end{methoddesc}
***************
*** 618,623 ****
If the increased precision needed for the intermediate calculations exceeds
! the capabilities of the implementation then an Invalid operation condition
! is raised.
If, when raising to a negative power, an underflow occurs during the
--- 630,635 ----
If the increased precision needed for the intermediate calculations exceeds
! the capabilities of the implementation then an \constant{InvalidOperation}
! condition is signaled.
If, when raising to a negative power, an underflow occurs during the
***************
*** 666,670 ****
\begin{methoddesc}{substract}{x, y}
! Return the difference of \var{x} and \var{y}.
\end{methoddesc}
--- 678,682 ----
\begin{methoddesc}{substract}{x, y}
! Return the difference between \var{x} and \var{y}.
\end{methoddesc}
***************
*** 678,687 ****
\begin{methoddesc}{to_integral}{x}
! Rounds to the nearest integer, without signaling \constant{Inexact}
or \constant{Rounded}.
\end{methoddesc}
\begin{methoddesc}{to_sci_string}{}
! Converts a number to a string, using scientific notation.
\end{methoddesc}
--- 690,699 ----
\begin{methoddesc}{to_integral}{x}
! Rounds to the nearest integer without signaling \constant{Inexact}
or \constant{Rounded}.
\end{methoddesc}
\begin{methoddesc}{to_sci_string}{}
! Converts a number to a string using scientific notation.
\end{methoddesc}
***************
*** 696,700 ****
The context flag is incremented whenever the condition is encountered.
After the computation, flags may be checked for informational
! purposed (for instance, to determine whether a computation was exact).
After checking the flags, be sure to clear all flags before starting
the next computation.
--- 708,712 ----
The context flag is incremented whenever the condition is encountered.
After the computation, flags may be checked for informational
! purposes (for instance, to determine whether a computation was exact).
After checking the flags, be sure to clear all flags before starting
the next computation.
***************
*** 715,719 ****
\begin{classdesc*}{ConversionSyntax}
! Trying to convert a mal-formed string such as: \code{Decimal('jump')}.
Decimal converts only strings conforming to the numeric string
--- 727,731 ----
\begin{classdesc*}{ConversionSyntax}
! Trying to convert a malformed string such as: \code{Decimal('jump')}.
Decimal converts only strings conforming to the numeric string
***************
*** 795,799 ****
\begin{classdesc*}{Rounded}
! Rounding occurred though possibly not information was lost.
Signaled whenever rounding discards digits; even if those digits are
--- 807,811 ----
\begin{classdesc*}{Rounded}
! Rounding occurred though possibly no information was lost.
Signaled whenever rounding discards digits; even if those digits are
***************
*** 842,848 ****
The \function{getcontext()} function accesses a different \class{Context}
! object for each thread. Having separate contexts means that threads may make
! changes (such as \code{getcontext.prec=10}) without interfering with other
! threads and without needing mutexes.
Likewise, the \function{setcontext()} function automatically assigns its target
--- 854,860 ----
The \function{getcontext()} function accesses a different \class{Context}
! object for each thread. Having separate thread contexts means that threads
! may make changes (such as \code{getcontext.prec=10}) without interfering with
! other threads and without needing mutexes.
Likewise, the \function{setcontext()} function automatically assigns its target
***************
*** 860,864 ****
\begin{verbatim}
! # Set application wide defaults for all threads about to be launched
DefaultContext.prec=12
DefaultContext.rounding=ROUND_DOWN
--- 872,876 ----
\begin{verbatim}
! # Set applicationwide defaults for all threads about to be launched
DefaultContext.prec=12
DefaultContext.rounding=ROUND_DOWN
***************
*** 945,949 ****
c += t
getcontext().prec -= 2
! return c + 0
def exp(x):
--- 957,961 ----
c += t
getcontext().prec -= 2
! return c + 0 # Adding zero causes rounding to the new precision
def exp(x):
More information about the Python-checkins
mailing list