The difference between ABS () and Math.fabs () in Python

Source: Internet
Author: User

Description: The method in Python fabs(x) Returns the absolute value of x . Although similar to abs() a function, the following differences exist between the two functions:

    • abs()is a built-in function that is fabs() defined in a math module.
    • The fabs() function is only available for float and integer types, and abs() also for complex numbers .
    • ABS () return is float and int type, math.fabs () return is float type

Syntax: here is fabs() the syntax for the method:

Import Mathmath.fabs (x)

Note: This module cannot be accessed directly, requires calling math the module, and then math calls this function with a static object.

Parameters x is the incoming parameter.

return value The absolute value of the returned x .

Example

Import Math
A =-1
b =-1.3232
c = b
D = 1+1.0j
E = 3+4.0j
f =-230.13000
Print ("ABS () absolute value of output a:", ABS (a))
Print ("fabs () absolute value of output a", Math.fabs (a))
Print ("ABS () absolute value of output B:", ABS (b))
Print ("absolute value of output C:", Math.fabs (c))
Print ("absolute value of output D:", ABS (d))
Print ("absolute value of output e:", ABS (E))
# Print ("fabs () output e absolute value:", Math.fabs (e))
Print ("abs () output F absolute value:", ABS (f))
Print (the absolute value of the "fabs () output F:", Math.fabs (f))

Output

ABS () absolute value of output a: 1
Fabs () absolute value of output a 1.0
ABS () absolute value of output B: 1.3232
Absolute value of output C: 1.3232
Absolute value of output D: 1.4142135623730951
Absolute value of output E: 5.0
ABS () absolute value of output F: 230.13
Fabs () absolute value of output F: 230.13


The difference between ABS () and Math.fabs () in Python

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.