HomeLanguagesPython math library | isfinite() and remainder() method

Python math library | isfinite() and remainder() method

Python has math library and has many functions regarding to it. math.remainder() method returns an exact (floating) value as a remainder. Syntax:

math.remainder(x, y)

Time Complexity: O(1)

Auxiliary space: O(1)

For finite x and finite nonzero y, this is the difference x – n*y, where n is the closest integer to the exact value of the quotient x / y. If x / y is exactly halfway between two consecutive integers, the nearest even integer is used for n. The remainder r = remainder(x, y) thus always satisfies abs(r) <= 0.5 * abs(y). 

Python3




# Importing Math module
import math
 
# printing remainder of two values
print(math.remainder(5, 2))
print(math.remainder(10, 5))
print(math.remainder(12, 7))
print(math.remainder(6, 2))


Output:

1.0
0.0
-2.0
0.0

 

math.isfinite() function –

Syntax:

math.isfinite(x)

Time Complexity: O(1)

Auxiliary space: O(1)

math.isfinite() method returns True if x is neither an infinity nor a NaN, and False otherwise. (Note that 0.0 is considered finite.) 

Python3




# Importing Math module
import math
 
# printing remainder of two values
print(math.isfinite(5))
print(math.isfinite(float('nan')))
print(math.isfinite(-2.5))
print(math.isfinite(0.0))


Output:

True
False
True
True

Reference: Python Math Library

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

2 COMMENTS

Most Popular

Dominic
32688 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7057 POSTS0 COMMENTS
Nicole Veronica
12198 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12293 POSTS0 COMMENTS
Shaida Kate Naidoo
7182 POSTS0 COMMENTS
Ted Musemwa
7447 POSTS0 COMMENTS
Thapelo Manthata
7160 POSTS0 COMMENTS
Umr Jansen
7150 POSTS0 COMMENTS