Changeset 391 for python/trunk/Doc/library/math.rst
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Doc/library/math.rst
r2 r391 6 6 :synopsis: Mathematical functions (sin() etc.). 7 7 8 .. testsetup:: 9 10 from math import fsum 8 11 9 12 This module is always available. It provides access to the mathematical … … 34 37 .. function:: copysign(x, y) 35 38 36 Return *x* with the sign of *y*. ``copysign`` copies the sign bit of an IEEE37 754 float, ``copysign(1, -0.0)`` returns *-1.0*.39 Return *x* with the sign of *y*. On a platform that supports 40 signed zeros, ``copysign(1.0, -0.0)`` returns *-1.0*. 38 41 39 42 .. versionadded:: 2.6 … … 57 60 Return the floor of *x* as a float, the largest integer value less than or equal 58 61 to *x*. 59 60 .. versionchanged:: 2.661 Added :meth:`__floor__` delegation.62 62 63 63 … … 91 91 92 92 >>> sum([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1]) 93 0.999999999999999 8993 0.9999999999999999 94 94 >>> fsum([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1]) 95 95 1.0 … … 110 110 .. function:: isinf(x) 111 111 112 Check s if the float *x* is positive or negative infinite.112 Check if the float *x* is positive or negative infinity. 113 113 114 114 .. versionadded:: 2.6 … … 117 117 .. function:: isnan(x) 118 118 119 Checks if the float *x* is a NaN (not a number). NaNs are part of the 120 IEEE 754 standards. Operation like but not limited to ``inf * 0``, 121 ``inf / inf`` or any operation involving a NaN, e.g. ``nan * 1``, return 122 a NaN. 119 Check if the float *x* is a NaN (not a number). For more information 120 on NaNs, see the IEEE 754 standards. 123 121 124 122 .. versionadded:: 2.6 … … 139 137 .. function:: trunc(x) 140 138 141 Return the :class:`Real` value *x* truncated to an :class:`Integral` (usually 142 a long integer). Delegates to ``x.__trunc__()``. 139 Return the :class:`~numbers.Real` value *x* truncated to an 140 :class:`~numbers.Integral` (usually a long integer). Uses the 141 ``__trunc__`` method. 143 142 144 143 .. versionadded:: 2.6 … … 163 162 164 163 Return ``e**x``. 164 165 166 .. function:: expm1(x) 167 168 Return ``e**x - 1``. For small floats *x*, the subtraction in 169 ``exp(x) - 1`` can result in a significant loss of precision; the 170 :func:`expm1` function provides a way to compute this quantity to 171 full precision:: 172 173 >>> from math import exp, expm1 174 >>> exp(1e-5) - 1 # gives result accurate to 11 places 175 1.0000050000069649e-05 176 >>> expm1(1e-5) # result accurate to full precision 177 1.0000050000166668e-05 178 179 .. versionadded:: 2.7 165 180 166 181 … … 199 214 is undefined, and raises :exc:`ValueError`. 200 215 216 Unlike the built-in ``**`` operator, :func:`math.pow` converts both 217 its arguments to type :class:`float`. Use ``**`` or the built-in 218 :func:`pow` function for computing exact integer powers. 219 201 220 .. versionchanged:: 2.6 202 221 The outcome of ``1**nan`` and ``nan**0`` was undefined. … … 232 251 with the positive X axis. The point of :func:`atan2` is that the signs of both 233 252 inputs are known to it, so it can compute the correct quadrant for the angle. 234 For example, ``atan(1 ``)and ``atan2(1, 1)`` are both ``pi/4``, but ``atan2(-1,253 For example, ``atan(1)`` and ``atan2(1, 1)`` are both ``pi/4``, but ``atan2(-1, 235 254 -1)`` is ``-3*pi/4``. 236 255 … … 309 328 310 329 330 Special functions 331 ----------------- 332 333 .. function:: erf(x) 334 335 Return the error function at *x*. 336 337 .. versionadded:: 2.7 338 339 340 .. function:: erfc(x) 341 342 Return the complementary error function at *x*. 343 344 .. versionadded:: 2.7 345 346 347 .. function:: gamma(x) 348 349 Return the Gamma function at *x*. 350 351 .. versionadded:: 2.7 352 353 354 .. function:: lgamma(x) 355 356 Return the natural logarithm of the absolute value of the Gamma 357 function at *x*. 358 359 .. versionadded:: 2.7 360 361 311 362 Constants 312 363 --------- … … 314 365 .. data:: pi 315 366 316 The mathematical constant *pi*.367 The mathematical constant Ï = 3.141592..., to available precision. 317 368 318 369 319 370 .. data:: e 320 371 321 The mathematical constant *e*.372 The mathematical constant e = 2.718281..., to available precision. 322 373 323 374 … … 325 376 326 377 The :mod:`math` module consists mostly of thin wrappers around the platform C 327 math library functions. Behavior in exceptional cases is loosely specified328 by the C standards, and Python inherits much of its math-function329 error-reporting behavior from the platform C implementation. As a result,330 the specific exceptions raised in error cases (and even whether some331 a rguments are considered to be exceptional at all) are not defined in any332 useful cross-platform or cross-release way. For example, whether333 ``math.log(0)`` returns ``-Inf`` or raises :exc:`ValueError` or334 :exc:`OverflowError` isn't defined, and in cases where ``math.log(0)`` raises335 :exc:`OverflowError`, ``math.log(0L)`` may raise :exc:`ValueError` instead.336 337 All functions return a quiet *NaN* if at least one of the args is *NaN*. 338 Signaling *NaN*\s raise an exception. The exception type still depends on the339 platform and libm implementation. It's usually :exc:`ValueError` for *EDOM*340 and :exc:`OverflowError` for errno *ERANGE*.378 math library functions. Behavior in exceptional cases follows Annex F of 379 the C99 standard where appropriate. The current implementation will raise 380 :exc:`ValueError` for invalid operations like ``sqrt(-1.0)`` or ``log(0.0)`` 381 (where C99 Annex F recommends signaling invalid operation or divide-by-zero), 382 and :exc:`OverflowError` for results that overflow (for example, 383 ``exp(1000.0)``). A NaN will not be returned from any of the functions 384 above unless one or more of the input arguments was a NaN; in that case, 385 most functions will return a NaN, but (again following C99 Annex F) there 386 are some exceptions to this rule, for example ``pow(float('nan'), 0.0)`` or 387 ``hypot(float('nan'), float('inf'))``. 388 389 Note that Python makes no effort to distinguish signaling NaNs from 390 quiet NaNs, and behavior for signaling NaNs remains unspecified. 391 Typical behavior is to treat all NaNs as though they were quiet. 341 392 342 393 .. versionchanged:: 2.6 343 In earlier versions of Python the outcome of an operation with NaN as344 input depended on platform and libm implementation.394 Behavior in special cases now aims to follow C99 Annex F. In earlier 395 versions of Python the behavior in special cases was loosely specified. 345 396 346 397
Note:
See TracChangeset
for help on using the changeset viewer.