Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add multiprecision rational number support Implemented classes and traits for multiprecision rational number arithmetic, comparisons, and conversions. Added extensive unit tests to validate the functionality and included configuration in CMakeLists. * Implement rational arithmetic operations in RationalArithmetic This commit adds methods for in-place addition, subtraction, multiplication, and division of rational numbers using the GMP library. It ensures the methods check for non-null pointers before proceeding with operations to avoid null pointer dereference. * Add comparison functions to RationalComparison class Implemented functions for comparing rational numbers using GMP library. This includes checks for equality, less than, less than or equal to, greater than, and greater than or equal to. Assertions ensure the pointers are not null before performing comparisons. * Add mathematical operations to RationalNumber Implement the RationalNumber class with functions for abs, pow, real, imaginary, and from_rational operations. Utilize GMP library for precise arithmetic and add necessary assertions for debugging. * Enable trait retrieval for RationalType Restored the switch statement in `get_builtin_trait` to enable retrieval of built-in traits for comparison, arithmetic, and number operations. Added a fallback with `RPY_UNREACHABLE_RETURN(nullptr)` to handle unexpected cases safely. * Trim null bytes from rational number string buffer This change ensures that null bytes at the end of the string buffer are removed after converting the rational number to a string. This prevents potential issues with string display or further processing where null bytes might interfere. * Remove redundant newline in rational_type.cpp A redundant newline was removed from the buffer initialization section. This change improves the code readability by keeping the formatting neat and consistent. No functional code was affected by this modification. * Add integer arithmetic and type system to multiprecision types Implemented IntegerType and IntegerArithmetic classes along with relevant header and source files. Added unit tests for the IntegerType class and integrated them into the build system. Updated rational_type test for consistency. * Fix uninitialized integer_type in MultiPrecisionTypes constructor Added initialization of `integer_type` with `IntegerType::get()` to ensure it is not left as a null pointer. Also included a call to `ignore * Rename IntegerType identifiers for clarity Changed the return values in IntegerType's name and id methods to more accurately reflect the class's purpose. 'integer' was renamed to 'MultiPrecisionInteger' and 'api' was renamed to 'apz' to avoid ambiguity. * Update boolean flag in IntegerType configuration Changed the last configuration flag from true to false to correct the object initialization settings. This adjustment ensures the proper handling of edge cases during multiprecision integer operations. * Update include guards in multiprecision headers Renamed include guards to prevent naming collisions and align with the ROUGHPY_GENERICS_INTERNAL naming convention. This change increases consistency and reduces the risk of conflicts in larger projects. * Implement basic arithmetic operations for IntegerArithmetic. Introduce unsafe_add_inplace, unsafe_sub_inplace, unsafe_mul_inplace, and a stub for unsafe_div_inplace using GMP. Ensured non-null safety checks and consistent operation behavior. * Add IntegerComparison and IntegerNumber classes Introduce IntegerComparison and IntegerNumber classes to handle integer-specific comparison and numeric operations. Updates also include modifications to CMakeLists.txt to include new files in the build process. * Refactor IntegerType class initialization This commit introduces explicit constructors for `IntegerArithmetic`, `IntegerComparison`, and `IntegerNumber` within the `IntegerType` class, improving clarity and initialization logic. It also corrects some formatting issues in the related header files. * Refactor IntegerType parsing and trait retrieval Enhanced IntegerType parsing by adding a null check and using mpz_set_str for string conversion. Refactored trait retrieval by returning appropriate built-in traits and adding a default unreachable return statement. * Update vcpkg configuration and dependencies Updated the vcpkg baseline and refined dependency listings. Also added new dependencies mpfr (v4.2.1) and updated gmp (v6.3.0#1) to ensure compatibility and performance improvements. Mpir is removed because it did not fix the intermittent bug on Windows. * Add MPFR library support Introduce a new CMake module to find and configure the MPFR library. Updated main CMakeLists.txt and multiprecision_types to include and link MPFR accordingly. * Add unit tests for MultiPrecision float type This commit introduces a new test file, `test_float_type.cpp`, which includes a series of unit tests for the MultiPrecision float type. The tests cover various properties and functionalities, such as identity, reference counting, basic properties, and a range of arithmetic, comparison, and number-like operations. * Remove unnecessary blank line in test file This commit removes an extra blank line in the `test_integer_type.cpp` file to improve code readability. No functionality or logic in the code has been impacted by this change. * Add MPFloatType for multiprecision floating-point support This commit introduces the MPFloatType class, enabling multiprecision floating-point operations within the generics module. The related header and implementation files were added, and necessary CMakeLists.txt adjustments were made to include the new files. Unit tests for MPFloatType have also been integrated into the test suite. * Refactor string conversion for mpz_set_str Changed the conversion of the input string to use a temporary `std::string` object before passing it to `mpz_set_str`. This ensures the function works correctly with different string encodings and formats, improving reliability. * Refactor precision data type in MPFloatType class Changed the precision parameter in the `MPFloatType` constructor from `size_t` to `int`. This modification includes an added member variable and ensures that 32 bits of precision is sufficient for the intended calculations. * Change precision parameter type to int in float_type Modified the `float_type` method to accept an `int` for precision instead of `size_t`. This change ensures consistency across different parts of the codebase and avoids potential issues with type mismatches. * Fix rational number parsing with temporary string variable Previously, passing a string directly to `mpq_set_str` could lead to unexpected behavior. This change introduces a temporary string variable to ensure proper handling and conversion. * Refactor MPFloatType class to improve functionality Revised the constructor, member functions, and internal logic of the `MPFloatType` class. Enhanced memory allocation, deallocation, copy/move operations, and parsing methods for better precision handling and error management. Updated return types and added assertions for robustness. * Update hash calculation in mpz_hash.h Changed hash initialization to use the mp_size_t of the integer. This ensures a more unique starting hash value and potentially improves collision resistance in hash computations. * Add cleanup and hash logic for MPFloatType Implemented proper resource cleanup in the `MPFloatType::destroy_range` and display functions to ensure proper memory management. Added hash calculation logic to generate hashes based on the significand and exponent of the floating-point value. This enhances both functionality and robustness of MPFloatType operations. * Add FloatArithmetic class for multiprecision float operations Introduced `FloatArithmetic` class that extends `ArithmeticTrait` and provides inplace arithmetic operations (addition, subtraction, multiplication, division) using MPFR library. This allows for multiprecision floating-point arithmetic within the generics module. * Add FloatComparison class for multiprecision float operations Introduced the FloatComparison class inheriting from ComparisonTrait to handle various comparison operations on multiprecision floating-point numbers using MPFR. Implemented methods for equality, less than, less than or equal to, greater than, and greater than or equal to comparisons. This facilitates robust and precise floating-point arithmetic comparisons within the generics module. * Add new float arithmetic and comparison source files Included float_arithmetic.cpp, float_arithmetic.h, float_comparison.cpp, and float_comparison.h to the project. This update supports floating-point operations and comparisons, enhancing the multiprecision capabilities of the platform. * Add FloatNumber class for multiprecision arithmetic. Introduced FloatNumber class in float_number.h and float_number.cpp to handle multiprecision floating-point operations. Updated CMakeLists.txt to include the new files. This class supports basic arithmetic functions such as sqrt, pow, exp, and log. * Add float type header and return precision object Included the necessary header for float type and modified the function to return a new MPFloatType object based on precision input. Changed the parameter type from `size_t` to `int` for consistency. * Enhance MPFloatType with traits and ensure precision check Introduce arithmetic, comparison, and number traits to MPFloatType, allowing better trait handling and checks. Add a precision limit check to ensure it does not exceed MPFR_PREC_MAX. Implement name and ID retrieval methods to provide clearer type identification. * Add unreachable return to handle all cases Ensure function returns a value by adding RPY_UNREACHABLE_RETURN(false) in the default switch case. This addresses potential undefined behavior and improves code safety. * Update test expectations for ref_count and Div operation Adjust test expectations to match the correct reference count and check for the presence of the Division operation. These changes ensure the tests accurately reflect the current functionality and object states. * Remove conditional block for generics directory The generics subdirectory is now always included in the build process, regardless of the ROUGHPY_EXPERIMENTAL flag. This change simplifies the CMake configuration by eliminating unnecessary conditional checks. * Refactor `get_type` function declaration. Moved the implementation details of the `get_type` function to a separate location. This change enhances the readability and maintainability of the code by separating the function declaration from its implementation. * Improve number parsing with `std::from_chars` specialization Refactor number parsing logic to handle floating-point and integer types separately using `std::from_chars`. Added a debug assertion to ensure the entire string is parsed correctly. * Refactor compiler version macros for clarity Simplified the version macro logic by introducing a generic RPY_COMPILER_VERSION macro. This change ensures consistency across different compiler detections and improves readability. * Refactor support for older Clang and macOS compilers Added conditional inclusion of <sstream> and a workaround for older Clang and AppleClang lacking `std::from_chars` for floating points. Cleaned up white spaces and simplified conditional checks to improve code readability. * Fix type conversion in legacy compilers. Updated the handling of string conversion using istringstream to ensure compatibility with older versions of Clang and AppleClang. This addresses parsing issues with floating point values when from_chars is not available. * Simplify type parsing in builtin_type_methods.h Removed conditional compilation directives and updated the logic to streamline type parsing for integral, float, and double values. This improves code readability and maintains compatibility with compilers lacking `std::from_chars` support for floating-point values. * Include <cstdlib> and mark exceptions as unused Add the <cstdlib> header for proper functionality and mark caught exceptions as unused by using the RPY_UNUSED macro to prevent compiler warnings for unused variables. * Fix unreachable return warning in comparison trait Update RPY_UNREACHABLE_RETURN to return false instead of void to eliminate unreachable return warning in the ComparisonTraitImpl class. This ensures compliance with modern compiler standards and improves code robustness. * Refactor CMakeLists: Consolidate targets into RoughPy_Platform Simplify the CMake configurations by merging RoughPy_Generics_BuiltinType and RoughPy_Generics_Multiprecision targets into RoughPy_Platform. This change reduces redundancy and centralizes target management, improving maintainability. * Mark `backup_display` for export Add the `ROUGHPY_PLATFORM_EXPORT` macro to the `backup_display` function to ensure it is properly exported for external use. This change allows the function to be accessible outside the compilation unit, facilitating integration with other modules or shared libraries. * Enhance GMP find module with imported target support Updated the FindGMP.cmake module to use pkg_check_modules with IMPORTED_TARGET, ensuring the creation of the GMP::GMP target when the package is found. This streamlined the handling of GMP library properties and reduced the redundancy in code, making it easier to manage and maintain.
- Loading branch information