mirror of
https://github.com/boostorg/multiprecision.git
synced 2026-01-19 04:22:11 +00:00
* Update Jamfile.v2 * Update introduction.qbk * Update tutorial.qbk * Update tutorial_cpp_int.qbk * Update tutorial_gmp_int.qbk * Update tutorial_tommath.qbk * Update integer_examples.cpp * Update tutorial_cpp_bin_float.qbk * Update tutorial_cpp_dec_float.qbk * Update tutorial_gmp_float.qbk * Update tutorial_mpfr_float.qbk * Update tutorial_float128.qbk * Update tutorial_float_builtin_ctor.qbk * Update big_seventh.cpp * Update tutorial_float_eg.qbk * Update floating_point_examples.cpp * Update mpfr_precision.cpp * Update gauss_laguerre_quadrature.cpp * Update tutorial_interval_mpfi.qbk * Update tutorial_cpp_complex.qbk * Update tutorial_mpc_complex.qbk * Update tutorial_float128_complex.qbk * Update tutorial_complex_adaptor.qbk * Update tutorial_rational.qbk * Update tutorial_tommath_rational.qbk * Update tutorial_logged_adaptor.qbk * Update tutorial_debug_adaptor.qbk * Update tutorial_visualizers.qbk * Update tutorial_fwd.qbk * Update tutorial_conversions.qbk * Update tutorial_random.qbk * Update random_snips.cpp * Update tutorial_constexpr.qbk * Update tutorial_import_export.qbk * Update cpp_int_import_export.cpp * Update tutorial_mixed_precision.qbk * Update tutorial_variable_precision.qbk * Update scoped_precision_example.cpp * Update tutorial_numeric_limits.qbk * Update tutorial_numeric_limits.qbk * Update numeric_limits_snips.cpp * Update numeric_limits_snips.cpp * Update tutorial_numeric_limits.qbk * Update numeric_limits_snips.cpp * Update numeric_limits_snips.cpp * Update tutorial_io.qbk * Update reference_number.qbk * Update reference_cpp_bin_float.qbk * Update reference_cpp_double_fp_backend.qbk * Update reference_internal_support.qbk * Update reference_backend_requirements.qbk * Update performance.qbk * Update performance_overhead.qbk * Update performance_real_world.qbk * Update performance_integer_real_world.qbk * Update performance_rational_real_world.qbk * Update reference_number.qbk * Update tutorial_numeric_limits.qbk * Update reference_backend_requirements.qbk
51 lines
1.9 KiB
Plaintext
51 lines
1.9 KiB
Plaintext
[/
|
|
Copyright 2011 - 2020 John Maddock.
|
|
Copyright 2013 - 2019 Paul A. Bristow.
|
|
Copyright 2013 Christopher Kormanyos.
|
|
|
|
Distributed under the Boost Software License, Version 1.0.
|
|
(See accompanying file LICENSE_1_0.txt or copy at
|
|
http://www.boost.org/LICENSE_1_0.txt).
|
|
]
|
|
|
|
[section:tommath_rational tommath_rational]
|
|
|
|
`#include <boost/multiprecision/tommath.hpp>`
|
|
|
|
namespace boost{ namespace multiprecision{
|
|
|
|
typedef rational_adpater<tommath_int> tommath_rational;
|
|
typedef number<tommath_rational > tom_rational;
|
|
|
|
}} // namespaces
|
|
|
|
The `tommath_rational` back-end is used via the typedef `boost::multiprecision::tom_rational`. It acts as a thin wrapper around
|
|
`boost::rational<tom_int>`
|
|
to provide a rational number type that is a drop-in replacement for the native C++ number types, but with unlimited precision.
|
|
|
|
The advantage of using this type rather than `boost::rational<tom_int>` directly is that it is expression-template enabled,
|
|
greatly reducing the number of temporaries created in complex expressions.
|
|
|
|
There are also non-member functions:
|
|
|
|
tom_int numerator(const tom_rational&);
|
|
tom_int denominator(const tom_rational&);
|
|
|
|
which return the numerator and denominator of the number.
|
|
|
|
Things you should know when using this type:
|
|
|
|
* Default constructed `tom_rational`s have the value zero (this is the inherited Boost.Rational behavior).
|
|
* Division by zero results in a `std::overflow_error` being thrown.
|
|
* Conversion from a string results in a `std::runtime_error` being thrown if the string can not be
|
|
interpreted as a valid rational number.
|
|
* No changes are made to [tommath]'s global state, so this type can safely coexist with other [tommath] code.
|
|
* Performance of this type has been found to be pretty poor - this needs further investigation - but it appears that Boost.Rational
|
|
needs some improvement in this area.
|
|
|
|
[h5 Example:]
|
|
|
|
[mp_rat_eg]
|
|
|
|
[endsect] [/section:tommath_rational tommath_rational]
|