Skip to content

Commit

Permalink
modular params: part 1 #38
Browse files Browse the repository at this point in the history
  • Loading branch information
Luannet committed Oct 21, 2020
1 parent b28bef1 commit f6f3c76
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 1 deletion.
30 changes: 30 additions & 0 deletions doc/tutorial_barrett_params.qbk
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[/
]
[section:barrett_params Barrett params]
``
namespace boost {
namespace multiprecision {
namespace backends {
template <typename Backend>
class barrett_params;
}}
``
The class `barrett_params` is inherited from the [link boost_multiprecision.tut.modular.modular_adaptor.modular_params.base_params `base_params`] class.
This class perform the modular reductions using the Barrett reduction algorithm.
The constructor of class set the base_params and precomputed values.
The function `inline void eval_barret_reduce` compute the number that need to be reduced on modulo.
Inside of the fuction only multiplications, subtractions, additions and shifts are used.

[h2 API barrett_params]
[h3 Constructors]
* `barrett_params()`
* `barrett_params(const Number& p)`
[h3 Operators]
* `barrett_params& operator=(const V& v)`
[h3 Getters]
`inline const number_type& mu() const`
[h3 Class member functions]
* `inline void eval_barret_reduce(Backend& result) const`
This void perform the Barrett's modular reduction.

[endsect][/section:barrett_params barrett_params]
24 changes: 24 additions & 0 deletions doc/tutorial_base_params.qbk
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[/
]

[section:base_params Base_params]
``
namespace boost {
namespace multiprecision {
namespace backends {

template <typename Backend>
class base_params;
}}
``
The class `base_params` initialize the module for modular calculations.

[h2 API base_params]
[h3 Constructors]
* `base_params()`
* `base_params(const Number& p)`

[h3 Getter]
`const number_type& mod() const` - return the modules value.

[endsect] [/section:base_params base_params]
28 changes: 27 additions & 1 deletion doc/tutorial_modular_params.qbk
Original file line number Diff line number Diff line change
@@ -1,14 +1,40 @@
[/
]

[section:modular_params Modular_params]
[section:modular_params Modular params]

``
namespace boost {
namespace multiprecision {

template <typename Backend>
class modular_params;
}}
``

The class `modular_params` is inherited from the
[link boost_multiprecision.tut.modular.modular_adaptor.modular_params.montgomery_params `public backends::montgomery_params<Backend>`]
and [link boost_multiprecision.tut.modular.modular_adaptor.modular_params.barrett_params `public backends::barrett_params<Backend>`]classes.
[include tutorial_montgomery_params.qbk]
[include tutorial_barrett_params.qbk]
[include tutorial_base_params.qbk]

[h2 API modular_params]
[h3 Constructors]
* `modular_params()`
* `modular_params(const Number& p)`
[h3 Operators]
* `modular_params& operator=(const modular_params<Backend>& v)`
* `modular_params& operator=(const Number& v)`
* `operator number<BackendT, ExpressionTemplates>()`
* `friend std::ostream& operator<<(std::ostream& o, modular_params<Backend> const& a)`
[h3 Getters]
* `number_type get_mod() const`
[h3 Class member functions]
* `void reduce(Backend& result) const`
This void perform the Montgomery's modular reduction for odd numbers and Barrett's modular reductions for even.
* `void adjust_modular(Backend& result)`
* `void adjust_regular(Backend& result, const Backend& input) const`
* `int compare(const modular_params<Backend>& o) const`

[endsect] [/section:modular_params modular_params]
33 changes: 33 additions & 0 deletions doc/tutorial_montgomery_params.qbk
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[/
]
[section:montgomery_params Montgomery params]
``
namespace boost {
namespace multiprecision {
namespace backends {
template <typename Backend>
class montgomery_params;
}}}
``
The class `montgomery_params` is inherited from the [link boost_multiprecision.tut.modular.modular_adaptor.modular_params.base_params `base_params`] class.
This class perform the modular reductions using the Montgomery reduction algorithm.
The constructor of class set the base_params and precomputed values.
The function `inline void eval_montgomery_reduce` compute the number that need to be reduced on modulo.
Inside of the fuction only multiplications, subtractions, additions and shifts are used.


[h2 API barrett_params]
[h3 Constructors]
* `montgomery_params()`
* `montgomery_params(const Number& p)`
[h3 Operators]
* `montgomery_params& operator=(const V& v)`
[h3 Getters]
* `inline const number_type& r2() const `
* `inline limb_type p_dash() const `
* `inline size_t p_words() const`
[h3 Class member functions]
* `inline void eval_montgomery_reduce(Backend& result) const`
This void perform the Montgomery's modular reduction.

[endsect][/section:montgomery_params montgomery_params]

0 comments on commit f6f3c76

Please sign in to comment.