{"id":25447,"date":"2021-11-10T14:59:49","date_gmt":"2021-11-10T09:29:49","guid":{"rendered":"https:\/\/python-programs.com\/?p=25447"},"modified":"2021-11-14T15:02:47","modified_gmt":"2021-11-14T09:32:47","slug":"python-cmath-isclose-method-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-cmath-isclose-method-with-examples\/","title":{"rendered":"Python cmath.isclose() Method with Examples"},"content":{"rendered":"

cmath.isclose() Method in Python:<\/strong><\/p>\n

The cmath.isclose() method determines whether or not two complex values are close. This method gives the following Boolean value: If the values are close, True; otherwise, False.<\/p>\n

To determine whether the values are close, this method employs either a relative tolerance or an absolute tolerance.<\/p>\n

It compares the values using the following formula:<\/p>\n

abs(a-b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol)<\/p>\n

Syntax:<\/strong><\/p>\n

cmath.isclose(a, b, rel_tol= value, abs_tol= value)<\/pre>\n

Parameters<\/strong><\/p>\n

a:<\/strong> This is Required. The first value used to determine closeness<\/p>\n

b:<\/strong> This is Required. The second value used to determine closeness<\/p>\n

rel_tol:<\/strong> This is Optional. It is relative tolerance. It is the greatest (maximum) possible difference between values a and b. 1e-09 is the default value.<\/p>\n

abs_tol:<\/strong> This is Optional. The absolute minimum tolerance. It is used to compare values close to zero. The value must be greater than zero.<\/p>\n

Return Value:<\/strong><\/p>\n

Returns a true or false value. If the values are close, True; otherwise, False.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given first Complex Number = 3+4j\r\nGiven second Complex Number = 3+4j<\/pre>\n

Output:<\/strong><\/p>\n

Checking if the given two complex values are close or not = True<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given first Complex Number = 5+2j\r\nGiven second Complex Number = 5+26j<\/pre>\n

Output:<\/strong><\/p>\n

Checking if the given two complex values are close or not = False<\/pre>\n

cmath.isclose() Method with Examples in Python<\/h2>\n