xiaoxiang781216 commented on code in PR #19891: URL: https://github.com/apache/nuttx/pull/19891#discussion_r3800291874
########## include/cxx/bits/std_abs.h: ########## @@ -0,0 +1,64 @@ +//*************************************************************************** +// include/cxx/bits/std_abs.h +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. The +// ASF licenses this file to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance with the +// License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations +// under the License. +// +//*************************************************************************** + +#ifndef __INCLUDE_CXX_BITS_STD_ABS +#define __INCLUDE_CXX_BITS_STD_ABS + +//*************************************************************************** +// Included Files +//*************************************************************************** + +#include <nuttx/config.h> +#include <stdlib.h> + +#undef abs + +//*************************************************************************** +// Namespace +//*************************************************************************** + +namespace std +{ + using ::abs; + + constexpr float abs(float x) + { + return __builtin_fabsf(x); Review Comment: let's call fabsf instead ########## include/cxx/bits/std_abs.h: ########## @@ -0,0 +1,64 @@ +//*************************************************************************** +// include/cxx/bits/std_abs.h Review Comment: merge into cstdlib ########## include/cxx/cmath: ########## @@ -40,6 +40,7 @@ #else # include <math.h> +# include <bits/std_abs.h> Review Comment: why need expose c++ function in c compatible header file ########## include/cxx/bits/std_abs.h: ########## @@ -0,0 +1,64 @@ +//*************************************************************************** +// include/cxx/bits/std_abs.h +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. The +// ASF licenses this file to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance with the +// License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations +// under the License. +// +//*************************************************************************** + +#ifndef __INCLUDE_CXX_BITS_STD_ABS +#define __INCLUDE_CXX_BITS_STD_ABS + +//*************************************************************************** +// Included Files +//*************************************************************************** + +#include <nuttx/config.h> +#include <stdlib.h> + +#undef abs + +//*************************************************************************** +// Namespace +//*************************************************************************** + +namespace std +{ + using ::abs; + + constexpr float abs(float x) + { + return __builtin_fabsf(x); + } + +#ifdef CONFIG_HAVE_DOUBLE + constexpr double abs(double x) + { + return __builtin_fabs(x); + } +#endif + +#ifdef CONFIG_HAVE_LONG_DOUBLE + constexpr long double abs(long double x) + { + return __builtin_fabsl(x); Review Comment: ditto ########## include/cxx/bits/std_abs.h: ########## @@ -0,0 +1,64 @@ +//*************************************************************************** +// include/cxx/bits/std_abs.h +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. The +// ASF licenses this file to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance with the +// License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations +// under the License. +// +//*************************************************************************** + +#ifndef __INCLUDE_CXX_BITS_STD_ABS +#define __INCLUDE_CXX_BITS_STD_ABS + +//*************************************************************************** +// Included Files +//*************************************************************************** + +#include <nuttx/config.h> +#include <stdlib.h> + +#undef abs + +//*************************************************************************** +// Namespace +//*************************************************************************** + +namespace std +{ + using ::abs; + + constexpr float abs(float x) + { + return __builtin_fabsf(x); + } + +#ifdef CONFIG_HAVE_DOUBLE + constexpr double abs(double x) + { + return __builtin_fabs(x); Review Comment: ditto -- 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]
