mpflanzer opened a new pull request, #19891:
URL: https://github.com/apache/nuttx/pull/19891

   ## Summary
   
   The floating point overloads of `std::abs` are defined in `cstdlib` and 
`cmath` according to the C++ standard: 
https://en.cppreference.com/cpp/numeric/math/fabs
   
   Without these new definitions the `int std::abs(int)` function was selected 
for all argument types resulting in a truncation of the result for floating 
point arguments.
   
   ## Impact
   
   Improved compatibility with the C++ standard
   
   ## Testing
   
   ```
   #include <cstdio>
   #include <cstdlib>
   
   extern "C" int main(int argc, FAR char *argv[]) {
   
     printf("::abs(4.2) = %f\n", (double)::abs(4.2));
     printf("std::abs(4.2) = %f\n", (double)std::abs(4.2));
   
     return 0;
   }
   ```
   
   Without the changes running this program results in the following output:
   
   ```
   ::abs(4.2) = 4.000000
   std::abs(4.2) = 4.000000
   ```
   
   That is compliant for `::abs` but not for `std::abs`.
   
   With the changes the right overload of `std::abs` is selected and the output 
is:
   
   ```
   ::abs(4.2) = 4.000000
   std::abs(4.2) = 4.200000
   ```
   
   Tested with the `qemu-armv7a:nsh` config


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to