Bug 248190 - std::fabs is missing from <cstdlib> in 12.1-STABLE for C++17+
Summary: std::fabs is missing from <cstdlib> in 12.1-STABLE for C++17+
Status: Closed Not A Bug
Alias: None
Product: Base System
Classification: Unclassified
Component: standards (show other bugs)
Version: 12.1-STABLE
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-standards (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-07-22 18:58 UTC by Yuri Victorovich
Modified: 2020-07-22 19:51 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Yuri Victorovich freebsd_committer freebsd_triage 2020-07-22 18:58:26 UTC
Here https://en.cppreference.com/w/cpp/numeric/math/fabs it says that std::fabs is defined since C++11.

However, this program fails:
> #include <cstdlib>
> 
> int main() {
> 	std::fabs(1.);
> }



> $ c++ -std=c++11 -o fabs fabs.cpp
> fabs.cpp:5:7: error: no member named 'fabs' in namespace 'std'
>         std::fabs(1.);
>         ~~~~~^


FreeBSD 12.1-STABLE r359625
Comment 1 Yuri Pankov freebsd_committer freebsd_triage 2020-07-22 19:18:32 UTC
The link you provided says "Defined in header <cmath>", try that?
Comment 2 Yuri Victorovich freebsd_committer freebsd_triage 2020-07-22 19:33:03 UTC
(In reply to Yuri Pankov from comment #1)

The link says:
Defined in header <cmath>
Defined in header <cstdlib>  (since C++17)

Thank you for pointing this out.

I changed the subject. std::fabs is only missing from <cstdlib> for C++17+.

> #include <cstdlib>
> 
> int main() {
> 	std::fabs(1.);
> }


> $ c++ -std=c++17 -o fabs fabs.cpp
> fabs.cpp:4:7: error: no member named 'fabs' in namespace 'std'
>         std::fabs(1.);
>         ~~~~~^
> 1 error generated.
Comment 3 Yuri Pankov freebsd_committer freebsd_triage 2020-07-22 19:40:04 UTC
(In reply to Yuri Victorovich from comment #2)
Quoting:
--------
Defined in header <cmath>
Defined in header <cstdlib> (since C++17)
float       abs( float arg );
double      abs( double arg );
long double abs( long double arg );

Defined in header <cmath>
float       fabs ( float arg );
float       fabsf( float arg ); (since C++11)
--------

I read it as only abs() being defined in <cstdlib> since c++17, and fabs()/fabsf() having their own preceding comment about being in <cmath>, no?
Comment 4 Yuri Victorovich freebsd_committer freebsd_triage 2020-07-22 19:51:36 UTC
(In reply to Yuri Pankov from comment #3)

Ah, I see. My bad, I mis-read it.

Thank you for making this clear.

Best,
Yuri