abs function equivalent in c++

조회 수: 2 (최근 30일)
Manu Chaudhary
Manu Chaudhary 2022년 9월 24일
댓글: Walter Roberson 2022년 9월 24일
Hi everyone, I am presently struggling with converting a matlab prototype code into a c++ equivalent. I am struggling with the abs function.
What should I do in C++/C to get the similar output?

답변 (1개)

Walter Roberson
Walter Roberson 2022년 9월 24일
https://cplusplus.com/reference/cstdlib/abs/
In C++ abs() is overloaded and for double precision will call fabs()
fabs() was not a formal part of C, but it was common for C vendors to provide fabs(). It was common for fabs to be implemented as a macro, but that led to arguments, especially as ieee 754 double precision defines an fabs hardware operation that does not require any branching.
  댓글 수: 3
Manu Chaudhary
Manu Chaudhary 2022년 9월 24일
편집: Manu Chaudhary 2022년 9월 24일
Thank you for great help. Your solution worked.
Walter Roberson
Walter Roberson 2022년 9월 24일
https://en.cppreference.com/w/cpp/numeric/complex shows the complex class for C++ and shows using a suffix of i for imaginary part, and shows abs() as the function name

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Write C++ Functions Callable from MATLAB (MEX Files)에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by