| Start |
|---|
| Rounding: round, floor, ceil, trunc In addition to the built-in
Warning!As with any floating-point representation, some fractions cannot be represented exactly. This can lead to some unexpected rounding behavior. Warning about the floor, trunc, and integer division of negative numbersPython (and C++ and Java) round away from zero for negative numbers. Consider: |
Trigonometry Calculating the length of the hypotenuseConverting degrees to/from radiansAll All results of the inverse trigonometic functions return the result in radians, so you may need to convert it back to degrees: Sine, cosine, tangent and inverse functionsApart from the Hyperbolic sine, cosine and tangent |
| Logarithms
When used with two arguments, |
| Constants
Python 3.5 and higher have constants for infinity and NaN ("not a number"). The older syntax of passing a string to |
| Infinity and NaN ("not a number") In all versions of Python, we can represent infinity and NaN ("not a number") as follows: In Python 3.5 and higher, we can also use the defined constants The string representations display as We can test for either positive or negative infinity with the We can test specifically for positive infinity or for negative infinity by direct comparison: Python 3.2 and higher also allows checking for finiteness: Comparison operators work as expected for positive and negative infinity: But if an arithmetic expression produces a value larger than the maximum that can be represented as a However division by zero does not give a result of infinity (or negative infinity where appropriate), rather it raises a Arithmetic operations on infinity just give infinite results, or sometimes NaN: NaN is never equal to anything, not even itself. We can test for it is with the NaN always compares as "not equal", but never less than or greater than: Arithmetic operations on NaN always give NaN. This includes multiplication by -1: there is no "negative NaN". There is one subtle difference between the old |
| Pow for faster exponentiation Using the timeit module from the command line: The built-in |
| Copying signs In Python 2.6 and higher, |
| Imaginary Numbers Imaginary numbers in Python are represented by a "j" or "J" trailing the target number. |
| Complex numbers and the cmath module The First of all, complex numbers are a numeric type that is part of the Python language itself rather than being provided by a library class. Thus we don't need to Note that we use We must use We have the The built-in functions The But for most functions we do need the module, for instance Naturally the behavior of Functions are provided to convert to and from polar coordinates: The mathematical field of complex analysis is beyond the scope of this example, but many functions in the complex plane have a "branch cut", usually along the real axis or the imaginary axis. Most modern platforms support "signed zero" as specified in IEEE 754, which provides continuity of those functions on both sides of the branch cut. The following example is from the Python documentation: The In addition to The constants The Likewise, the Note there is no In Python 3.5 and higher, there is an |
Read Article
https://develop.horje.com/learn/1434/reference