Skip to content

Commit fa136d5

Browse files
authored
Bring version 0.1.1 into main (#12)
* Add support for builtin detection * Update comments to be more eye catching * Add clang-cl and apple clang support * Fix bug with MSVC where not checking for nan * Remove msvc specific code in favor of generic approach * Prepare for 0.1.0 release. * Add doxygen docs * Finalize min/max * Add todo for later work on remquo * Cleanup main for 0.1.0 release * Bring standard back to C++17 * Minor cleanup to cmake list * Prep files for v0.1.0 release * Prepare for 0.1.0 release. * Add doxygen docs * Finalize min/max * Add todo for later work on remquo * Cleanup main for 0.1.0 release * Bring standard back to C++17 * Minor cleanup to cmake list * Prep files for v0.1.0 release * Bring everything in * Remove artifacts that mistakenly got pushed to main * Implement isgreater * Implement isgreaterequal * Implement isless * Implement islessequal * Implement islessgreater * Implement isnormal * Implement isunordered * Add test cases for all new compare functions * Add boilerplate code for future unit tests * Update progress * A lot of work done so far on log * log now far more efficient and accurate * Update readme progress * Continue work on log for double * remove unnecessary include * remove msvc section of unlikely * improve variable names * remove old log impl * Cleanup double implementation of log * cleanup of log details and add more comments. * Finalize work on log function * Update current progress * Fix bug with ±0 in log * Update test cases to cover all major edge cases * Move to correct folder * Add headers for log and log2 * Remove dependency on Threads * Initial addition of Contribution Guide * Cleanup README and add extra information * Update project version to v0.1.1 * Add top12 bits function for upcoming work * Finalize work with log function * Initial working revision of log2 * Push current work. Need to revise log2 to resolve bugs later. * Initial implementation of lerp * Fix scope bug * remove the direct use of cmath. * Update include to use cfloat instead of float.h * Cleanup macros and fix minor bugs * Fix bug where we were improperly assigning a correct value to the wrong variable * Update docs to mention not accounting for big-endian * Add comment to mention we are mirroring impl from cmath * Remove MSVC fallback that was inconsistent with every other impl * Add additional helpers for future work * Add test for static_assert support and some additional tests * Finalize implementation of log2 * Remove static_assert for now * Update README.md
1 parent 867fc9d commit fa136d5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+2617
-121
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.18)
22

33
enable_language(CXX)
44

5-
set(CCMATH_BUILD_VERSION 0.1.0)
5+
set(CCMATH_BUILD_VERSION 0.1.1)
66
set(INTERNAL_PROJ_DEFAULT_NAME ccmath)
77

88
project(${INTERNAL_PROJ_DEFAULT_NAME} VERSION ${CCMATH_BUILD_VERSION})

CONTRIBUTING.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Contribution Guidelines
2+
3+
WIP

README.md

+39-28
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ ccmath is a C++17 library that provides a re-implementation of the standard `<cm
44

55
## Features
66

7-
- **constexpr Compatibility**: All functions provided by ccmath are implemented as `constexpr`, allowing them to be evaluated at compile time when used with constant expressions.
7+
- **Full constexpr Compatibility**: All functions provided by ccmath are implemented as `constexpr`, allowing them to be evaluated at compile time when used with constant expressions.
88

99
- **Standard Math Functions**: ccmath provides a comprehensive set of mathematical functions similar to those in the standard `<cmath>` library, including trigonometric, exponential, logarithmic, and other common mathematical operations. If `<cmath>` has it then it is likely ccmath has implemented it.
1010

11-
- **Performance Optimization**: By leveraging constexpr, ccmath aims to optimize performance by computing mathematical expressions at compile time where possible, reducing runtime overhead.
11+
- **Performance Optimization**: By leveraging constexpr, ccmath aims to optimize performance by computing mathematical expressions at compile time when possible, reducing runtime overhead.
1212

1313
- **No External Dependencies**: ccmath has no external dependencies and only requires a C++17-compliant compiler.
1414

@@ -33,40 +33,51 @@ int main() {
3333
ccmath has a comprehensive cmake setup and can be easily included in your project using fetchcontent like so:
3434

3535
```cmake
36+
cmake_minimum_required(VERSION 3.11) # FetchContent is new in version 3.11.
37+
3638
include(FetchContent)
3739
FetchContent_Declare(
3840
ccmath
3941
GIT_REPOSITORY https://github.com/Rinzii/ccmath.git
40-
GIT_TAG main
42+
GIT_TAG v0.1.0 # Replace with the version you want to use
4143
)
4244
FetchContent_MakeAvailable(ccmath)
45+
46+
target_link_libraries(main PRIVATE ccmath::ccmath)
4347
```
4448

45-
## Compatability
49+
## Compiler Support
50+
* GCC 11.1+
51+
* Clang 9.0.0+
52+
* AppleClang 14.0.3+ (Lowest tested version)
53+
* MSVC 19.26+
54+
* Intel DPC++ 2022.0.0+
55+
* Nvidia HPC SDK 22.7+ (Lowest tested version)
4656

47-
ccmath is designed to be compatible with any C++17-compliant compiler. It should work seamlessly with popular compilers such as GCC, Clang, and MSVC.
57+
> [!NOTE]
58+
> Currently working on finding manners to lower these requirements.
4859
4960
## Contributing
5061

51-
Contributions to ccmath are welcome! If you encounter any bugs, have suggestions for improvements, or would like to contribute new features, feel free to open an issue or submit a pull request!
62+
CCmath is an open-source project, and it needs your help to go on growing and improving. If you want to get involved and suggest some additional features, file a bug report or submit a patch, please have a look at the contribution guidelines.
5263

53-
## Implementation Progress (Sub Sections)
54-
| Section | % done | In Progress? | Notes? | Planned Completion Version |
64+
## Implementation Progress (Modules)
65+
| Module | % done | In Progress? | Notes? | Planned Completion Version |
5566
|--------------------|--------|--------------|---------------------------------------------------------------------------|----------------------------|
56-
| Basic | 91 | | Remquo is being pushed back to a later release due to technical problems. | v0.1.0 |
57-
| Compare | 40 | | |
58-
| Exponential | 0 | | |
67+
| Basic | 91 | | Remquo is being pushed back to a later release due to technical problems. | v0.1.0 (Released) |
68+
| Compare | 100 | | | v0.2.0 |
69+
| Exponential | 33 || | v0.2.0 |
5970
| Float Manipulation | 0 | | |
6071
| Hyperbolic | 0 | | |
6172
| Nearest | 15 | | |
6273
| Power | 5 | | |
6374
| Special Functions | 0 | | |
6475
| Trigonometric | 0 | | |
65-
| Misc Functions | 0 | | |
76+
| Misc Functions | 10 | | |
6677

67-
> Last Updated: Mar 02, 2024
78+
> Last Updated: Mar 09, 2024
6879
69-
## Implementation Progress (All Functions)
80+
## Implementation Progress (Functions)
7081

7182
| Feature | % done | TODO |
7283
|----------------|--------|------------------------------------------------------------------------------------------|
@@ -79,22 +90,22 @@ Contributions to ccmath are welcome! If you encounter any bugs, have suggestions
7990
| remquo | 40 | Partially implemented, but being pushed back to later release due to technical problems. |
8091
| fpclassify | 100 | |
8192
| isfinite | 100 | |
82-
| isgreater | 0 | Implement function |
83-
| isgreaterequal | 0 | Implement function |
84-
| isinf | 98 | Improve documentation |
85-
| isless | 0 | Implement function |
86-
| islessequal | 0 | Implement function |
87-
| islessgreater | 0 | Implement function |
88-
| isnan | 95 | Add more support for built-in functions and improve documentation |
89-
| isnormal | 0 | Implement function |
90-
| isunordered | 0 | Implement function |
91-
| signbit | 90 | Add more fallbacks and builtin support if possible and improve reliability with MSVC |
93+
| isgreater | 100 | |
94+
| isgreaterequal | 100 | |
95+
| isinf | 100 | Improve documentation |
96+
| isless | 100 | |
97+
| islessequal | 100 | |
98+
| islessgreater | 100 | |
99+
| isnan | 100 | Functional, need improved documentation and more test cases. |
100+
| isnormal | 100 | |
101+
| isunordered | 100 | |
102+
| signbit | 100 | Need to find manner of implementing signbit on lower versions of MSVC. |
92103
| exp | 35 | Continue implementation process and add documentation and tests |
93104
| exp2 | 0 | Implement function |
94105
| expm1 | 0 | Implement function |
95-
| log | 0 | Implement function |
106+
| log | 100 | Functional, but fallbacks without requiring recent compiler versions is desired. |
96107
| log1p | 0 | Implement function |
97-
| log2 | 0 | Implement function |
108+
| log2 | 100 | Functional, but fallbacks without requiring recent compiler versions is desired. |
98109
| log10 | 0 | Implement function |
99110
| copysign | 0 | Implement function |
100111
| frexp | 0 | Implement function |
@@ -149,10 +160,10 @@ Contributions to ccmath are welcome! If you encounter any bugs, have suggestions
149160
| sin | 0 | Implement function |
150161
| tan | 0 | Implement function |
151162
| gamma | 0 | Implement function |
152-
| lerp | 0 | Implement function |
163+
| lerp | 30 | Need to finish implementation process along with handling edge cases and promotion. |
153164
| lgamma | 0 | Implement function |
154165

155-
> Last Updated: Mar 02, 2024
166+
> Last Updated: Mar 09, 2024
156167
157168

158169
## License
File renamed without changes.

ccmath_headers.cmake

+21
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ set(ccmath_internal_helpers_headers
55
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/helpers/make_mantisa.hpp
66
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/helpers/not_null.hpp
77
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/helpers/fpclassify_helper.hpp
8+
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/helpers/pow_integral.hpp
9+
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/helpers/find_number.hpp
10+
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/helpers/is_odd.hpp
11+
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/helpers/exponentiation_helpers.hpp
12+
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/helpers/bits.hpp
13+
)
14+
15+
set(ccmath_internal_predef_headers
16+
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/predef/unlikely.hpp
817
)
918

1019
set(ccmath_internal_setup_headers
@@ -27,6 +36,7 @@ set(ccmath_internal_utility_headers
2736

2837
set(ccmath_internal_headers
2938
${ccmath_internal_helpers_headers}
39+
${ccmath_internal_predef_headers}
3040
${ccmath_internal_setup_headers}
3141
${ccmath_internal_typetraits_headers}
3242
${ccmath_internal_utility_headers}
@@ -61,7 +71,17 @@ set(ccmath_detail_compare_headers
6171
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/detail/compare/signbit.hpp
6272
)
6373

74+
set(ccmath_detail_exponential_details_headers
75+
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/detail/exponential/details/log_float_impl.hpp
76+
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/detail/exponential/details/log_double_impl.hpp
77+
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/detail/exponential/details/log_data.hpp
78+
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/detail/exponential/details/log2_float_impl.hpp
79+
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/detail/exponential/details/log2_double_impl.hpp
80+
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/detail/exponential/details/log2_data.hpp
81+
)
82+
6483
set(ccmath_detail_exponential_headers
84+
${ccmath_detail_exponential_details_headers}
6585
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/detail/exponential/exp.hpp
6686
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/detail/exponential/exp2.hpp
6787
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/detail/exponential/expm1.hpp
@@ -172,6 +192,7 @@ set(ccmath_root_headers
172192
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/special.hpp
173193
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/trig.hpp
174194
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/ccmath.hpp
195+
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/numbers.hpp
175196
)
176197

177198
set(ccmath_headers

ext/CMakeLists.txt

-7
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ if (CCMATH_BUILD_TEST)
3333
endif()
3434

3535

36-
37-
#find_package(Threads REQUIRED)
38-
3936
add_library(${PROJECT_NAME} INTERFACE)
4037
add_library(${INTERNAL_PROJ_DEFAULT_NAME}::ext ALIAS ${PROJECT_NAME})
4138

@@ -45,7 +42,3 @@ if(CCMATH_BUILD_TEST)
4542
)
4643
endif ()
4744

48-
# TODO: May not actually require this. Later decide if I want to remove it.
49-
target_link_libraries(${PROJECT_NAME} INTERFACE
50-
Threads::Threads
51-
)

include/ccmath/detail/compare/isgreater.hpp

+33
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,40 @@
88

99
#pragma once
1010

11+
#include <type_traits>
12+
1113
namespace ccm
1214
{
15+
/**
16+
* @brief Checks if the first argument is greater than the second.
17+
* @tparam T Type of the values to compare.
18+
* @param x A floating-point or integer value.
19+
* @param y A floating-point or integer value.
20+
* @return true if the first argument is greater than the second, false otherwise.
21+
*/
22+
template <typename T>
23+
inline constexpr bool isgreater(T x, T y) noexcept
24+
{
25+
return x > y;
26+
}
27+
28+
/**
29+
* @brief Checks if the first argument is greater than the second.
30+
* @tparam T Type of the left-hand side.
31+
* @tparam U Type of the right-hand side.
32+
* @param x Value of the left-hand side of the comparison.
33+
* @param y Value of the right-hand side of the comparison.
34+
* @return true if the first argument is greater than the second, false otherwise.
35+
*/
36+
template <typename T, typename U>
37+
inline constexpr bool isgreater(T x, U y) noexcept
38+
{
39+
// Find the common type of the two arguments
40+
using shared_type = std::common_type_t<T, U>;
1341

42+
// Then cast the arguments to the common type and call the single argument version
43+
return static_cast<shared_type>(isgreater<shared_type>(static_cast<shared_type>(x), static_cast<shared_type>(y)));
44+
}
1445
} // namespace ccm
46+
47+
/// @ingroup compare

include/ccmath/detail/compare/isgreaterequal.hpp

+33
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,40 @@
88

99
#pragma once
1010

11+
#include <type_traits>
12+
1113
namespace ccm
1214
{
15+
/**
16+
* @brief Checks if the first argument is greater than or equal to the second.
17+
* @tparam T Type of the values to compare.
18+
* @param x A floating-point or integer value.
19+
* @param y A floating-point or integer value.
20+
* @return true if the first argument is greater than or equal to the second, false otherwise.
21+
*/
22+
template <typename T>
23+
inline constexpr bool isgreaterequal(T x, T y) noexcept
24+
{
25+
return x >= y;
26+
}
27+
28+
/**
29+
* @brief Checks if the first argument is greater than or equal to the second.
30+
* @tparam T Type of the left-hand side.
31+
* @tparam U Type of the right-hand side.
32+
* @param x Value of the left-hand side of the comparison.
33+
* @param y Value of the right-hand side of the comparison.
34+
* @return true if the first argument is greater than or equal to the second, false otherwise.
35+
*/
36+
template <typename T, typename U>
37+
inline constexpr bool isgreaterequal(T x, U y) noexcept
38+
{
39+
// Find the common type of the two arguments
40+
using shared_type = std::common_type_t<T, U>;
1341

42+
// Then cast the arguments to the common type and call the single argument version
43+
return static_cast<shared_type>(isgreaterequal<shared_type>(static_cast<shared_type>(x), static_cast<shared_type>(y)));
44+
}
1445
} // namespace ccm
46+
47+
/// @ingroup compare

include/ccmath/detail/compare/isless.hpp

+33
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,40 @@
88

99
#pragma once
1010

11+
#include <type_traits>
12+
1113
namespace ccm
1214
{
15+
/**
16+
* @brief Checks if the first argument is less than the second.
17+
* @tparam T Type of the values to compare.
18+
* @param x A floating-point or integer value.
19+
* @param y A floating-point or integer value.
20+
* @return true if the first argument is less than the second, false otherwise.
21+
*/
22+
template <typename T>
23+
inline constexpr bool isless(T x, T y) noexcept
24+
{
25+
return x < y;
26+
}
27+
28+
/**
29+
* @brief Checks if the first argument is less than the second.
30+
* @tparam T Type of the left-hand side.
31+
* @tparam U Type of the right-hand side.
32+
* @param x Value of the left-hand side of the comparison.
33+
* @param y Value of the right-hand side of the comparison.
34+
* @return true if the first argument is less than the second, false otherwise.
35+
*/
36+
template <typename T, typename U>
37+
inline constexpr bool isless(T x, U y) noexcept
38+
{
39+
// Find the common type of the two arguments
40+
using shared_type = std::common_type_t<T, U>;
1341

42+
// Then cast the arguments to the common type and call the single argument version
43+
return static_cast<shared_type>(isless<shared_type>(static_cast<shared_type>(x), static_cast<shared_type>(y)));
44+
}
1445
} // namespace ccm
46+
47+
/// @ingroup compare

include/ccmath/detail/compare/islessequal.hpp

+33
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,40 @@
88

99
#pragma once
1010

11+
#include <type_traits>
12+
1113
namespace ccm
1214
{
15+
/**
16+
* @brief Checks if the first argument is less than or equal to the second.
17+
* @tparam T Type of the values to compare.
18+
* @param x A floating-point or integer value.
19+
* @param y A floating-point or integer value.
20+
* @return true if the first argument is less than or equal to the second, false otherwise.
21+
*/
22+
template <typename T>
23+
inline constexpr bool islessequal(T x, T y) noexcept
24+
{
25+
return x <= y;
26+
}
27+
28+
/**
29+
* @brief Checks if the first argument is less than or equal to the second.
30+
* @tparam T Type of the left-hand side.
31+
* @tparam U Type of the right-hand side.
32+
* @param x Value of the left-hand side of the comparison.
33+
* @param y Value of the right-hand side of the comparison.
34+
* @return true if the first argument is less than or equal to the second, false otherwise.
35+
*/
36+
template <typename T, typename U>
37+
inline constexpr bool islessequal(T x, U y) noexcept
38+
{
39+
// Find the common type of the two arguments
40+
using shared_type = std::common_type_t<T, U>;
1341

42+
// Then cast the arguments to the common type and call the single argument version
43+
return static_cast<shared_type>(islessequal<shared_type>(static_cast<shared_type>(x), static_cast<shared_type>(y)));
44+
}
1445
} // namespace ccm
46+
47+
/// @ingroup compare

0 commit comments

Comments
 (0)