How to get absolute value from double - c-language

后端 未结 5 1675
时光说笑
时光说笑 2020-12-28 11:27

I want the absolute-value from a negative double - and I thought the abs-function was as easy to use as in java - but NOT!

It seems that the abs

相关标签:
5条回答
  • 2020-12-28 12:05

    It's worth noting that Java can overload a method such as abs so that it works with an integer or a double. In C, overloading doesn't exist, so you need different functions for integer versus double.

    0 讨论(0)
  • 2020-12-28 12:12

    I have found that using cabs(double), cabsf(float), cabsl(long double), __cabsf(float), __cabs(double), __cabsf(long double) is the solution

    0 讨论(0)
  • 2020-12-28 12:13

    Use fabs instead of abs to find absolute value of double (or float) data types. Include the <math.h> header for fabs function.

    double d1 = fabs(-3.8951);
    
    0 讨论(0)
  • 2020-12-28 12:20

    Use fabs() (in math.h) to get absolute-value for double:

    double d1 = fabs(-3.8951);
    
    0 讨论(0)
  •   //use fabs()
      double sum_primary_diagonal=0;
      double sum_secondary_diagonal=0;
      double difference = fabs(sum_primary_diagonal - sum_secondary_diagonal);
    
    0 讨论(0)
提交回复
热议问题