<commit_before>.. _rational_reference:

Multiprecision rationals
========================

.. versionadded:: 0.3

*#include <mp++/rational.hpp>*

The ``rational`` class
----------------------

.. doxygenclass:: mppp::rational
   :members:

Concepts
--------

.. cpp:concept:: template <typename T, std::size_t SSize> mppp::RationalInteroperable

   This concept is satisfied if the type ``T`` can interoperate with a :cpp:class:`~mppp::rational`
   with static size ``SSize``. Specifically, this concept will be ``true`` if ``T`` satisfies
   :cpp:concept:`~mppp::CppInteroperable` or :cpp:concept:`~mppp::CppComplex`,
   or it is an :cpp:class:`~mppp::integer` with static size ``SSize``.

   A corresponding boolean type trait called ``is_rational_interoperable`` is also available (even if the compiler does
   not support concepts).

.. cpp:concept:: template <typename T, std::size_t SSize> mppp::RationalCvrInteroperable

   This concept is satisfied if the type ``T``, after the removal of reference and cv qualifiers,
   satisfies :cpp:concept:`~mppp::RationalInteroperable`.

.. cpp:concept:: template <typename T, std::size_t SSize> mppp::RationalIntegralInteroperable

   This concept is satisfied if either:

   * ``T`` satisfies :cpp:concept:`~mppp::CppIntegralInteroperable`, or
   * ``T`` is an :cpp:class:`~mppp::integer` with static size ``SSize``.

   A corresponding boolean type trait called ``is_rational_integral_interoperable`` is also available (even if the compiler does
   not support concepts).

.. cpp:concept:: template <typename T, std::size_t SSize> mppp::RationalCvrIntegralInteroperable

   This concept is satisfied if the type ``T``, after the removal of reference and cv qualifiers,
   satisfies :cpp:concept:`~mppp::RationalIntegralInteroperable`.

.. cpp:concept:: template <typename T, typename U> mppp::RationalOpTypes

   This concept is satisfied if the types ``T`` and ``U`` are suitable for use in the
   generic binary :ref:`operators <rational_operators>` and :ref:`functions <rational_functions>`
   involving :cpp:class:`~mppp::rational`. Specifically, the concept will be ``true`` if either:

   * ``T`` and ``U`` are both :cpp:class:`~mppp::rational` with the same static size ``SSize``, or
   * one type is a :cpp:class:`~mppp::rational` and the other is a :cpp:concept:`~mppp::RationalInteroperable`
     type.

   A corresponding boolean type trait called ``are_rational_op_types`` is also available (even if the compiler does
   not support concepts).

.. _rational_functions:

Functions
---------

Much of the functionality of the :cpp:class:`~mppp::rational` class is exposed
via plain functions. These functions
mimic the `GMP API <https://gmplib.org/manual/Rational-Number-Functions.html>`__ where appropriate, but a variety of
convenience/generic overloads is provided as well.

.. _rational_assignment:

Assignment
~~~~~~~~~~

.. cpp:function:: template <std::size_t SSize> void mppp::swap(mppp::rational<SSize> &q1, mppp::rational<SSize> &q2) noexcept

   .. versionadded:: 0.15

   Swap.

   This function will efficiently swap the values of *q1* and *q2*.

   :param q1: the first argument.
   :param q2: the second argument.<commit_msg>Missing doc bit.<commit_after>.. _rational_reference:

Multiprecision rationals
========================

.. versionadded:: 0.3

*#include <mp++/rational.hpp>*

The ``rational`` class
----------------------

.. doxygenclass:: mppp::rational
   :members:

Concepts
--------

.. cpp:concept:: template <typename T, std::size_t SSize> mppp::RationalInteroperable

   This concept is satisfied if the type ``T`` can interoperate with a :cpp:class:`~mppp::rational`
   with static size ``SSize``. Specifically, this concept will be ``true`` if ``T`` satisfies
   :cpp:concept:`~mppp::CppInteroperable` or :cpp:concept:`~mppp::CppComplex`,
   or it is an :cpp:class:`~mppp::integer` with static size ``SSize``.

   A corresponding boolean type trait called ``is_rational_interoperable`` is also available (even if the compiler does
   not support concepts).

.. cpp:concept:: template <typename T, std::size_t SSize> mppp::RationalCvrInteroperable

   This concept is satisfied if the type ``T``, after the removal of reference and cv qualifiers,
   satisfies :cpp:concept:`~mppp::RationalInteroperable`.

.. cpp:concept:: template <typename T, std::size_t SSize> mppp::RationalIntegralInteroperable

   This concept is satisfied if either:

   * ``T`` satisfies :cpp:concept:`~mppp::CppIntegralInteroperable`, or
   * ``T`` is an :cpp:class:`~mppp::integer` with static size ``SSize``.

   A corresponding boolean type trait called ``is_rational_integral_interoperable`` is also available (even if the compiler does
   not support concepts).

.. cpp:concept:: template <typename T, std::size_t SSize> mppp::RationalCvrIntegralInteroperable

   This concept is satisfied if the type ``T``, after the removal of reference and cv qualifiers,
   satisfies :cpp:concept:`~mppp::RationalIntegralInteroperable`.

.. cpp:concept:: template <typename T, typename U> mppp::RationalOpTypes

   This concept is satisfied if the types ``T`` and ``U`` are suitable for use in the
   generic binary :ref:`operators <rational_operators>` and :ref:`functions <rational_functions>`
   involving :cpp:class:`~mppp::rational`. Specifically, the concept will be ``true`` if either:

   * ``T`` and ``U`` are both :cpp:class:`~mppp::rational` with the same static size ``SSize``, or
   * one type is a :cpp:class:`~mppp::rational` and the other is a :cpp:concept:`~mppp::RationalInteroperable`
     type.

   A corresponding boolean type trait called ``are_rational_op_types`` is also available (even if the compiler does
   not support concepts).

.. cpp:concept:: template <typename T, typename U> mppp::RationalRealOpTypes

   This concept will be ``true`` if:

   * ``T`` and ``U`` satisfy :cpp:concept:`~mppp::RationalOpTypes`, and
   * neither ``T`` nor ``U`` satisfy :cpp:concept:`~mppp::CppComplex`.

   A corresponding boolean type trait called ``are_rational_real_op_types`` is also available (even if the compiler does
   not support concepts).

.. _rational_functions:

Functions
---------

Much of the functionality of the :cpp:class:`~mppp::rational` class is exposed
via plain functions. These functions
mimic the `GMP API <https://gmplib.org/manual/Rational-Number-Functions.html>`__ where appropriate, but a variety of
convenience/generic overloads is provided as well.

.. _rational_assignment:

Assignment
~~~~~~~~~~

.. cpp:function:: template <std::size_t SSize> void mppp::swap(mppp::rational<SSize> &q1, mppp::rational<SSize> &q2) noexcept

   .. versionadded:: 0.15

   Swap.

   This function will efficiently swap the values of *q1* and *q2*.

   :param q1: the first argument.
   :param q2: the second argument.
{'fraction_non_alphanumeric': 0.1408016443987667, 'fraction_numerical': 0.0032300690060196743, 'mean_word_length': 4.758241758241758, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2607134', 'n_tokens_mistral': 2164, 'n_tokens_neox': 2056, 'n_words': 692}