summaryrefslogtreecommitdiff
path: root/libcxx/include/cmath
AgeCommit message (Collapse)Author
2025-05-08[libc++] Simplify __promote (#136101)Nikolas Klauser
This avoids instantiating an extra class for every variant `__promote` is used in.
2024-12-21[libc++][C++03] Use `__cxx03/` headers in C++03 mode (#109002)Nikolas Klauser
This patch implements the forwarding to frozen C++03 headers as discussed in https://discourse.llvm.org/t/rfc-freezing-c-03-headers-in-libc. In the RFC, we initially proposed selecting the right headers from the Clang driver, however consensus seemed to steer towards handling this in the library itself. This patch implements that direction. At a high level, the changes basically amount to making each public header look like this: ``` // inside <vector> #ifdef _LIBCPP_CXX03_LANG # include <__cxx03/vector> #else // normal <vector> content #endif ``` In most cases, public headers are simple umbrella headers so there isn't much code in the #else branch. In other cases, the #else branch contains the actual implementation of the header.
2024-12-10[libc++] Add #if 0 block to all the top-level headers (#119234)Nikolas Klauser
Including The frozen C++03 headers results in a lot of formatting changes in the main headers, so this splits these changes into a separate commit instead. This is part of https://discourse.llvm.org/t/rfc-freezing-c-03-headers-in-libc.
2024-08-29[libc++][NFC] Remove __constexpr_is{nan,finite} (#106205)Nikolas Klauser
They're never used in `constexpr` functions, so we can simply use `std::isnan` and `std::isfinite` instead.
2024-08-05[libc++][math] Fix undue overflowing of `std::hypot(x,y,z)` (#100820)PaulXiCao
This is in relation to mr #93350. It was merged to main, but reverted because of failing sanitizer builds on PowerPC. The fix includes replacing the hard-coded threshold constants (e.g. `__overflow_threshold`) for different floating-point sizes by a general computation using `std::ldexp`. Thus, it should now work for all architectures. This has the drawback of not being `constexpr` anymore as `std::ldexp` is not implemented as `constexpr` (even though the standard mandates it for C++23). Closes #92782
2024-07-24Revert "[libc++][math] Fix undue overflowing of `std::hypot(x,y,z)` (#93350)"Mitch Phillips
This reverts commit 9628777479a970db5d0c2d0b456dac6633864760. More details in https://github.com/llvm/llvm-project/pull/93350, but this broke the PowerPC sanitizer bots.
2024-07-23[libc++][math] Fix undue overflowing of `std::hypot(x,y,z)` (#93350)PaulXiCao
The 3-dimentionsional `std::hypot(x,y,z)` was sub-optimally implemented. This lead to possible over-/underflows in (intermediate) results which can be circumvented by this proposed change. The idea is to to scale the arguments (see linked issue for full discussion). Tests have been added for problematic over- and underflows. Closes #92782
2024-07-20[libc++][math] Mathematical Special Functions: Hermite Polynomial (#89982)PaulXiCao
Implementing the Hermite polynomials which are part of C++17's mathematical special functions. The goal is to get early feedback which will make implementing the other functions easier. Integration of functions in chunks (e.g. `std::hermite` at first, then `std::laguerre`, etc.) might make sense as well (also see note on boost.math below). I started out from this abandoned merge request: https://reviews.llvm.org/D58876 . The C++23 standard defines them in-terms of `/* floating-point type */` arguments. I have not looked into that. Note, there is still an ongoing discussion on discourse whether importing boost.math is an option.
2024-07-05[libc++] Use _Complex for multiplication and division of complex floating ↵Nikolas Klauser
point types (#83575) This significantly simplifies the implementation and improves the codegen. The only downside is that the accuracy can be marginally worse, but that is up to the compiler to decide with this change, which means it can be controlled by compiler flags. Differential Revision: https://reviews.llvm.org/D155312
2024-06-18[libc++][NFC] Run clang-format on libcxx/include again (#95874)Louis Dionne
As time went by, a few files have become mis-formatted w.r.t. clang-format. This was made worse by the fact that formatting was not being enforced in extensionless headers. This commit simply brings all of libcxx/include in-line with clang-format again. We might have to do this from time to time as we update our clang-format version, but frankly this is really low effort now that we've formatted everything once.
2024-06-18[libc++][NFC] Remove unnecessary parens in static_asserts (#95605)Nikolas Klauser
These were required a long time ago due to `static_assert` not actually being available in C++03. Now `static_assert` is simply mapped to `_Static_assert` in C++03, making the additional parens unnecessary.
2024-02-29[libc++] Clean up includes of <__assert> (#80091)Louis Dionne
Originally, we used __libcpp_verbose_abort to handle assertion failures. That function was declared from all public headers. Since we don't use that mechanism anymore, we don't need to declare __libcpp_verbose_abort from all public headers, and we can clean up a lot of unnecessary includes. This patch also moves the definition of the various assertion categories to the <__assert> header, since we now rely on regular IWYU for these assertion macros. rdar://105510916
2023-12-18[libc++] Format the code base (#74334)Louis Dionne
This patch runs clang-format on all of libcxx/include and libcxx/src, in accordance with the RFC discussed at [1]. Follow-up patches will format the benchmarks, the test suite and remaining parts of the code. I'm splitting this one into its own patch so the diff is a bit easier to review. This patch was generated with: find libcxx/include libcxx/src -type f \ | grep -v 'module.modulemap.in' \ | grep -v 'CMakeLists.txt' \ | grep -v 'README.txt' \ | grep -v 'libcxx.imp' \ | grep -v '__config_site.in' \ | xargs clang-format -i A Git merge driver is available in libcxx/utils/clang-format-merge-driver.sh to help resolve merge and rebase issues across these formatting changes. [1]: https://discourse.llvm.org/t/rfc-clang-formatting-all-of-libc-once-and-for-all
2023-12-13[libc++][NFC] Add a few explicit 'inline' keywords, mostly in <chrono> (#75234)Louis Dionne
Even though constexpr implicitly makes functions inline, we try not to rely on this implicit effect in the code base. We are mostly consistent about using `inline` on non-template free-functions to make it clear that we don't have an ODR violation. This patch simply fixes a few places where we didn't explicitly use inline on non-template free functions, presumably because they were constexpr. Fixes #75227
2023-12-04[libc++] Rename _LIBCPP_INLINE_VISIBILITY to _LIBCPP_HIDE_FROM_ABI (#74095)Louis Dionne
In preparation for running clang-format on the whole code base, we are also removing mentions of the legacy _LIBCPP_INLINE_VISIBILITY macro in favor of the newer _LIBCPP_HIDE_FROM_ABI. We're still leaving the definition of _LIBCPP_INLINE_VISIBILITY to avoid creating needless breakage in case some older patches are checked-in with mentions of the old macro. After we branch for LLVM 18, we can do another pass to clean up remaining uses of the macro that might have gotten introduced by mistake (if any) and remove the macro itself at the same time. This is just a minor convenience to smooth out the transition as much as possible. See https://discourse.llvm.org/t/rfc-clang-formatting-all-of-libc-once-and-for-all for the clang-format proposal.
2023-09-01[libc++][NFC] Refactor __enable_if return types to defaulted template parametersNikolas Klauser
This brings most of the enable_ifs in libc++ to the same style. It also has the nice side-effect of reducing the size of names of these symbols, since the depedent return type is shorter. Reviewed By: #libc, ldionne Spies: ldionne, libcxx-commits Differential Revision: https://reviews.llvm.org/D157787
2023-08-15[libc++][NFC] Refactor return type enable_ifs to defaulted template argumentsNikolas Klauser
This brings most of the enable_ifs in libc++ to the same style. It also has the nice side-effect of reducing the size of names of these symbols, since the depedent return type is shorter. Reviewed By: #libc, ldionne Spies: ldionne, libcxx-commits Differential Revision: https://reviews.llvm.org/D157736
2023-07-31[libc++] Granulaize math.h and move the functions to std::__mathNikolas Klauser
Reviewed By: #libc, Mordante Spies: Mordante, arichardson, libcxx-commits Differential Revision: https://reviews.llvm.org/D155258
2023-02-15[libc++][NFC] Replace _LIBCPP_STD_VER > x with _LIBCPP_STD_VER >= xNikolas Klauser
This change is almost fully mechanical. The only interesting change is in `generate_feature_test_macro_components.py` to generate `_LIBCPP_STD_VER >=` instead. To avoid churn in the git-blame this commit should be added to the `.git-blame-ignore-revs` once committed. Reviewed By: ldionne, var-const, #libc Spies: jloser, libcxx-commits, arichardson, arphaman, wenlei Differential Revision: https://reviews.llvm.org/D143962
2023-01-30[libc++] Add missing include promote.h in <cmath>Louis Dionne
As a fly-by, also remove a superfluous <cstddef> include in promote.h. Differential Revision: https://reviews.llvm.org/D142657
2023-01-12[libc++][NFC] Fix endif comments in cmathNikolas Klauser
2023-01-09[libc++] Add _LIBCPP_HIDE_FROM_ABI to __constexpr_logb and __constexpr_scalbnNikolas Klauser
2023-01-08[libc++] [C++20] [P0415] Constexpr for std::complex.Marek Kurdej
This patch adds constexpr to <complex> header: operators, member operators, and member functions (real, imag, norm, conj). https://eel.is/c++draft/complex.numbers https://wg21.link/p0415 Reviewed By: ldionne, #libc Spies: philnik, danilaml, Quuxplusone, wmaxey, arichardson, libcxx-commits Differential Revision: https://reviews.llvm.org/D79555
2022-12-23[libc++] Add custom clang-tidy checksNikolas Klauser
Reviewed By: #libc, ldionne Spies: jwakely, beanz, smeenai, cfe-commits, tschuett, avogelsgesang, Mordante, sstefan1, libcxx-commits, ldionne, mgorny, arichardson, miyuki Differential Revision: https://reviews.llvm.org/D131963
2022-12-23[libc++] Granularize <type_traits> includes in <compare>Nikolas Klauser
Reviewed By: Mordante, #libc Spies: libcxx-commits Differential Revision: https://reviews.llvm.org/D140480
2022-12-08[libc++][NFC] Rename __libcpp_*_or_builtin to __constexpr_*Nikolas Klauser
We normally use the `__libcpp_` prefix to backport functions, but that doesn't really make sense here. The functions are always available. Using `__constexpr_` makes the intended use of the functions clear. Reviewed By: Mordante, #libc Spies: libcxx-commits Differential Revision: https://reviews.llvm.org/D139521
2022-08-17[libc++] Diagnose when header search paths are set up incorrectlyLouis Dionne
An issue I often see in codebases compiled for unusual platforms is that header search paths are specified manually and are subtly wrong. For example, people will manually add `-isystem <some-toolchain>/usr/include`, which ends up messing up the layering of header search paths required by libc++ (because the C Standard Library now appears *before* libc++ in the search paths). Without this patch, this will end up causing compilation errors that are pretty inscrutable. This patch aims to improve the user experience by diagnosing this issue explicitly. In all cases I can think of, I would expect that a compilation error occur if these header search paths are not layered properly. This should only provide an explicit diagnostic instead of failing due to seemingly unrelated compilation errors. Differential Revision: https://reviews.llvm.org/D131441
2022-08-13[libc++] Add a bunch of missing _LIBCPP_HIDE_FROM_ABINikolas Klauser
Reviewed By: ldionne, Mordante, var-const, huixie90, #libc Spies: jloser, libcxx-commits, arichardson, miyuki Differential Revision: https://reviews.llvm.org/D129968
2022-07-08[libc++] Make parameter names consistent and enforce the naming style using ↵Nikolas Klauser
readability-identifier-naming Ensure that parameter names have the style `__lower_case` Reviewed By: ldionne, #libc Spies: aheejin, sstefan1, libcxx-commits, miyuki Differential Revision: https://reviews.llvm.org/D129051
2022-03-30[libc++] Ensure that all public C++ headers include <__assert>Louis Dionne
This patch changes the requirement for getting the declaration of the assertion handler from including <__assert> to including any public C++ header of the library. Note that C compatibility headers are excluded because we don't implement all the C headers ourselves -- some of them are taken straight from the C library, like assert.h. It also adds a generated test to check it. Furthermore, this new generated test is designed in a way that will make it possible to replace almost all the existing test-generation scripts with this system in upcoming patches. Differential Revision: https://reviews.llvm.org/D122506
2022-02-04[libc++] Normalize all our '#pragma GCC system_header', and regression-test.Arthur O'Dwyer
Now we'll notice if a header forgets to include this magic phrase. Differential Revision: https://reviews.llvm.org/D118800
2022-01-10[libc++] Alphabetize header #includes. NFCI.Arthur O'Dwyer
The NFC part of D116809. We still want to enforce this in CI, but the mechanism for that is still to-be-determined. Differential Revision: https://reviews.llvm.org/D116809
2022-01-07[libc++] Add missing templated version of `std::lerp`.Arthur O'Dwyer
Fixes #50806. Differential Revision: https://reviews.llvm.org/D116295
2021-12-08[libc++] Extract __clamp_to_integral to its own headerLouis Dionne
In addition to being more consistent with our approach for helpers, this solves an actual issue where <cmath> was using numeric_limits but never including the <limits> header directly. In a normal setup, this is not an issue because the <math.h> header included by <cmath> does include <limits>. However, I did stumble upon some code where that didn't work, most likely because they were placing their own <math.h> header in front of ours. I didn't bother investigating further. Differential Revision: https://reviews.llvm.org/D115282
2021-11-17[runtimes][NFC] Remove filenames at the top of the license noticeLouis Dionne
We've stopped doing it in libc++ for a while now because these names would end up rotting as we move things around and copy/paste stuff. This cleans up all the existing files so as to stop the spreading as people copy-paste headers around.
2021-09-08[libc++] Use enable_if_t instead of _EnableIfLouis Dionne
I just ran into a compiler error involving __bind_back and some overloads that were being disabled with _EnableIf. I noticed that the error message was quite bad and did not mention the reason for the overload being excluded. Specifically, the error looked like this: candidate template ignored: substitution failure [with _Args = <ContiguousView>]: no member named '_EnableIfImpl' in 'std::_MetaBase<false>' Instead, when using enable_if or enable_if_t, the compiler is clever and can produce better diagnostics, like so: candidate template ignored: requirement 'is_invocable_v< std::__bind_back_op<1, std::integer_sequence<unsigned long, 0>>, std::ranges::views::__transform::__fn &, std::tuple<PlusOne> &, ContiguousView>' was not satisfied [with _Args = <ContiguousView>] Basically, it tries to do a poor man's implementation of concepts, which is already a lot better than simply complaining about substitution failure. Hence, this commit uses enable_if_t instead of _EnableIf whenever possible. That is both more straightforward than using the internal helper, and also leads to better error messages in those cases. I understand the motivation for _EnableIf's implementation was to improve compile-time performance, however I believe striving to improve error messages is even more important for our QOI, hence this patch. Furthermore, it is unclear that _EnableIf actually improved compile-time performance in any noticeable way (see discussion in the review for details). Differential Revision: https://reviews.llvm.org/D108216
2021-07-27[libc++] Fix a few warnings in system headers with GCCLouis Dionne
This isn't fixing all of them, but at least it's making some progress. Differential Revision: https://reviews.llvm.org/D106283
2021-06-04[libc++] Use the using_if_exists attribute when providedLouis Dionne
As discussed on cfe-dev [1], use the using_if_exists Clang attribute when the compiler supports it. This makes it easier to port libc++ on top of new platforms that don't fully support the C Standard library. Previously, libc++ would fail to build when trying to import a missing declaration in a <cXXXX> header. With the attribute, the declaration will simply not be imported into namespace std, and hence it won't be available for libc++ to use. In many cases, the declarations were *not* actually required for libc++ to work (they were only surfaced for users to use them as std::XXXX), so not importing them into namespace std is acceptable. The same thing could be achieved by conscious usage of `#ifdef` along with platform detection, however that quickly creates a maintenance problem as libc++ is ported to new platforms. Furthermore, this problem is exacerbated when mixed with vendor internal-only platforms, which can lead to difficulties maintaining a downstream fork of the library. For the time being, we only use the using_if_exists attribute when it is supported. At some point in the future, we will start removing #ifdef paths that are unnecessary when the attribute is supported, and folks who need those #ifdef paths will be required to use a compiler that supports the attribute. [1]: http://lists.llvm.org/pipermail/cfe-dev/2020-June/066038.html Differential Revision: https://reviews.llvm.org/D90257
2021-04-20[libc++] NFC: Normalize `#endif //` comment indentationLouis Dionne
2021-04-17[libc++] Remove hard tabs, U+00AD, and U+200B from all libc++ headers. NFCI.Arthur O'Dwyer
2021-04-09[libc++] Fix abs and div overload issue for compilers on AIXjasonliu
Summary: AIX system's stdlib.h provide different overload of abs and div depending on compiler versions. For example, std::div(long, long) and std::abs(long) are not available from OS's stdlib.h when building with clang, but they are available when building with xlclang compiler. Therefore, we need to provide those extra overloads in libc++'s stdlib.h when OS's stdlib.h does not. Differential Revision: https://reviews.llvm.org/D99767
2020-12-01[libc++] Consistently replace `std::` qualification with `_VSTD::` or ↵Arthur O'Dwyer
nothing. NFCI. I used a lot of `git grep` to find places where `std::` was being used outside of comments and assert-messages. There were three outcomes: - Qualified function calls, e.g. `std::move` becomes `_VSTD::move`. This is the most common case. - Typenames that don't need qualification, e.g. `std::allocator` becomes `allocator`. Leaving these as `_VSTD::allocator` would also be fine, but I decided that removing the qualification is more consistent with existing practice. - Names that specifically need un-versioned `std::` qualification, or that I wasn't sure about. For example, I didn't touch any code in <atomic>, <math.h>, <new>, or any ext/ or experimental/ headers; and I didn't touch any instances of `std::type_info`. In some deduction guides, we were accidentally using `class Alloc = typename std::allocator<T>`, despite `std::allocator<T>`'s type-ness not being template-dependent. Because `std::allocator` is a qualified name, this did parse as we intended; but what we meant was simply `class Alloc = allocator<T>`. Differential Revision: https://reviews.llvm.org/D92250
2020-05-25[libc++] [LWG3201] Update status page: lerp should be marked noexcept.Marek Kurdej
Summary: Update status page and test synopsis. Add synopsis in <cmath>. Reviewed By: ldionne, #libc Differential Revision: https://reviews.llvm.org/D80456
2019-10-01[libc++] Harden usage of static_assert against C++03Louis Dionne
In C++03, we emulate static_assert with a macro, and we must parenthesize multiple arguments. llvm-svn: 373328
2019-09-04[libc++] Move __clamp_to_integral to <cmath>, and harden against min()/max() ↵Louis Dionne
macros llvm-svn: 370900
2019-06-23Apply new meta-programming traits throughout the library.Eric Fiselier
The new meta-programming primitives are lower cost than the old versions. This patch removes those old versions and switches libc++ to use the new ones. llvm-svn: 364160
2019-05-06Remove unneeded <algorithm> include in cmath.Eric Fiselier
It's a remnant from an earlier version of the lerp change and is unneeded. llvm-svn: 360098
2019-04-25Implement 'lerp'; which is the last bit of P0811. Mark that paper as complete.Marshall Clow
llvm-svn: 359211
2019-01-19Update more file headers across all of the LLVM projects in the monorepoChandler Carruth
to reflect the new license. These used slightly different spellings that defeated my regular expressions. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351648
2018-09-12Implement the infrastructure for feature-test macros. Very few actual ↵Marshall Clow
feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955 llvm-svn: 342073