Next, take a concrete look at the common functions and constants of this module.
Upper limit (x)
Returns the upper bound of x, that is, the smallest integer greater than or equal to x. Look at the example:
Floor (x)
Returns the downward rounding of x, which is the largest integer less than or equal to x. Look at the example:
Wafer factory (10)
Returns the absolute value of x. Look at the example:
fmod(x,y)
Returns the remainder of x/y, which is a floating-point number. Look at this example:
factorial
Returns the factorial of x. If x is not an integer or a negative number, a ValueError will be thrown. Look at this example:
Power (x, y)
Returns the y power of x. Look at the example:
Fsum (iterative)
Returns the sum of all elements in an iterator. Look at this example:
gcd(x,y)
Returns the greatest common divisor of integers x and y. Look at the example:
sqrt(x)
Returns the square root of x. Look at the example:
trunc(x)
Returns the integer part of x. Look at the example:
exp(x)
Returns the x power of e. Look at the example:
log(x[,base])
Returns the logarithm of x, and the base is e by default. Look at this example:
constant
Tan (x)
Returns the tangent of the x radian. Look at this example:
Atan (x)
Returns the arctangent of x. Look at the example:
Sin (x)
Returns the sine of x radians. Look at this example:
Asin (X)
Returns the arcsine of x. Look at the example:
cos(x)
Returns the cosine of x radians. Look at this example:
Aco (10)
Returns the arccosine of x. Look at the example:
Decimal module supports decimal floating-point operations with correct rounding. Compared with the built-in floating-point float, it can control the precision more accurately, and can provide support for fields with high precision requirements such as finance.
Decimal works in a separate context. You can use getcontext () to view the current context, as follows:
From the above results, we can see that prec=28, which is the default precision. We can use getcontext (). Prec = xxx resets the precision. Let's take a look at it through specific examples.
Elementary operation
Implementation results:
The above result is to use the default precision. Let's reset the accuracy and have a look again:
Implementation results:
The random module can generate random numbers. Let's take a look at its common functions.
Random ()
Returns a random floating-point number in the range of [0.0, 1.0]. Look at this example:
Uniforms (A and B)
Returns a random floating-point number in the range of [a, b]. Look at this example:
randint(a,b)
Returns a random integer in the range of [a, b]. Look at this example:
Randrange (start, stop [,step])
Returns a random integer with a step size in the range of [Start, Stop]. Look at this example:
Selection (order)
Returns a random element from the non-empty sequence seq. Look at this example:
Shuffle (x[, random])
Randomly scramble the sequence x. Look at the example:
Sample (population, k)
Returns a list of unique elements of length k selected from a non-repetitive random sampling population sequence or set. Look at this example:
Reference:
https://docs.python.org/3/library/numeric.html