130 lines
36 KiB
HTML
130 lines
36 KiB
HTML
<!-- HTML header for doxygen 1.8.18-->
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
|
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
|
|
<meta name="generator" content="Doxygen 1.8.15"/>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
<title>OR-Tools: mathutil.h Source File</title>
|
|
<link href="tabs.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="jquery.js"></script>
|
|
<script type="text/javascript" src="dynsections.js"></script>
|
|
<link href="navtree.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="resize.js"></script>
|
|
<script type="text/javascript" src="navtreedata.js"></script>
|
|
<script type="text/javascript" src="navtree.js"></script>
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
|
|
$(document).ready(initResizable);
|
|
/* @license-end */</script>
|
|
<link href="search/search.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="search/searchdata.js"></script>
|
|
<script type="text/javascript" src="search/search.js"></script>
|
|
<link href="doxygen.css" rel="stylesheet" type="text/css" />
|
|
<link href="styleSheet.tmp.css" rel="stylesheet" type="text/css"/>
|
|
</head>
|
|
<body>
|
|
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
|
<div id="titlearea">
|
|
<table cellspacing="0" cellpadding="0">
|
|
<tbody>
|
|
<tr style="height: 56px;">
|
|
<td id="projectlogo"><img alt="Logo" src="orLogo.png"/></td>
|
|
<td id="projectalign" style="padding-left: 0.5em;">
|
|
<div id="projectname">OR-Tools
|
|
 <span id="projectnumber">9.2</span>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<!-- end header part -->
|
|
<!-- Generated by Doxygen 1.8.15 -->
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
|
|
var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|
/* @license-end */
|
|
</script>
|
|
<script type="text/javascript" src="menudata.js"></script>
|
|
<script type="text/javascript" src="menu.js"></script>
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
|
|
$(function() {
|
|
initMenu('',true,false,'search.php','Search');
|
|
$(document).ready(function() { init_search(); });
|
|
});
|
|
/* @license-end */</script>
|
|
<div id="main-nav"></div>
|
|
</div><!-- top -->
|
|
<div id="side-nav" class="ui-resizable side-nav-resizable">
|
|
<div id="nav-tree">
|
|
<div id="nav-tree-contents">
|
|
<div id="nav-sync" class="sync"></div>
|
|
</div>
|
|
</div>
|
|
<div id="splitbar" style="-moz-user-select:none;"
|
|
class="ui-resizable-handle">
|
|
</div>
|
|
</div>
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
|
|
$(document).ready(function(){initNavTree('mathutil_8h_source.html','');});
|
|
/* @license-end */
|
|
</script>
|
|
<div id="doc-content">
|
|
<!-- window showing the filter options -->
|
|
<div id="MSearchSelectWindow"
|
|
onmouseover="return searchBox.OnSearchSelectShow()"
|
|
onmouseout="return searchBox.OnSearchSelectHide()"
|
|
onkeydown="return searchBox.OnSearchSelectKey(event)">
|
|
</div>
|
|
|
|
<!-- iframe showing the search results (closed by default) -->
|
|
<div id="MSearchResultsWindow">
|
|
<iframe src="javascript:void(0)" frameborder="0"
|
|
name="MSearchResults" id="MSearchResults">
|
|
</iframe>
|
|
</div>
|
|
|
|
<div class="header">
|
|
<div class="headertitle">
|
|
<div class="title">mathutil.h</div> </div>
|
|
</div><!--header-->
|
|
<div class="contents">
|
|
<a href="mathutil_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span> <span class="comment">// Copyright 2010-2021 Google LLC</span></div><div class="line"><a name="l00002"></a><span class="lineno"> 2</span> <span class="comment">// Licensed under the Apache License, Version 2.0 (the "License");</span></div><div class="line"><a name="l00003"></a><span class="lineno"> 3</span> <span class="comment">// you may not use this file except in compliance with the License.</span></div><div class="line"><a name="l00004"></a><span class="lineno"> 4</span> <span class="comment">// You may obtain a copy of the License at</span></div><div class="line"><a name="l00005"></a><span class="lineno"> 5</span> <span class="comment">//</span></div><div class="line"><a name="l00006"></a><span class="lineno"> 6</span> <span class="comment">// http://www.apache.org/licenses/LICENSE-2.0</span></div><div class="line"><a name="l00007"></a><span class="lineno"> 7</span> <span class="comment">//</span></div><div class="line"><a name="l00008"></a><span class="lineno"> 8</span> <span class="comment">// Unless required by applicable law or agreed to in writing, software</span></div><div class="line"><a name="l00009"></a><span class="lineno"> 9</span> <span class="comment">// distributed under the License is distributed on an "AS IS" BASIS,</span></div><div class="line"><a name="l00010"></a><span class="lineno"> 10</span> <span class="comment">// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span></div><div class="line"><a name="l00011"></a><span class="lineno"> 11</span> <span class="comment">// See the License for the specific language governing permissions and</span></div><div class="line"><a name="l00012"></a><span class="lineno"> 12</span> <span class="comment">// limitations under the License.</span></div><div class="line"><a name="l00013"></a><span class="lineno"> 13</span> </div><div class="line"><a name="l00014"></a><span class="lineno"> 14</span> <span class="preprocessor">#ifndef OR_TOOLS_BASE_MATHUTIL_H_</span></div><div class="line"><a name="l00015"></a><span class="lineno"> 15</span> <span class="preprocessor">#define OR_TOOLS_BASE_MATHUTIL_H_</span></div><div class="line"><a name="l00016"></a><span class="lineno"> 16</span> </div><div class="line"><a name="l00017"></a><span class="lineno"> 17</span> <span class="preprocessor">#include <math.h></span></div><div class="line"><a name="l00018"></a><span class="lineno"> 18</span> </div><div class="line"><a name="l00019"></a><span class="lineno"> 19</span> <span class="preprocessor">#include <algorithm></span></div><div class="line"><a name="l00020"></a><span class="lineno"> 20</span> <span class="preprocessor">#include <vector></span></div><div class="line"><a name="l00021"></a><span class="lineno"> 21</span> </div><div class="line"><a name="l00022"></a><span class="lineno"> 22</span> <span class="preprocessor">#include "absl/base/casts.h"</span></div><div class="line"><a name="l00023"></a><span class="lineno"> 23</span> <span class="preprocessor">#include "<a class="code" href="basictypes_8h.html">ortools/base/basictypes.h</a>"</span></div><div class="line"><a name="l00024"></a><span class="lineno"> 24</span> <span class="preprocessor">#include "<a class="code" href="integral__types_8h.html">ortools/base/integral_types.h</a>"</span></div><div class="line"><a name="l00025"></a><span class="lineno"> 25</span> <span class="preprocessor">#include "<a class="code" href="base_2logging_8h.html">ortools/base/logging.h</a>"</span></div><div class="line"><a name="l00026"></a><span class="lineno"> 26</span> <span class="preprocessor">#include "<a class="code" href="macros_8h.html">ortools/base/macros.h</a>"</span></div><div class="line"><a name="l00027"></a><span class="lineno"> 27</span> </div><div class="line"><a name="l00028"></a><span class="lineno"> 28</span> <span class="keyword">namespace </span><a class="code" href="namespaceoperations__research.html">operations_research</a> {</div><div class="line"><a name="l00029"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_math_util.html"> 29</a></span> <span class="keyword">class </span><a class="code" href="classoperations__research_1_1_math_util.html">MathUtil</a> {</div><div class="line"><a name="l00030"></a><span class="lineno"> 30</span>  <span class="keyword">public</span>:</div><div class="line"><a name="l00031"></a><span class="lineno"> 31</span>  <span class="comment">// CeilOfRatio<IntegralType></span></div><div class="line"><a name="l00032"></a><span class="lineno"> 32</span>  <span class="comment">// FloorOfRatio<IntegralType></span></div><div class="line"><a name="l00033"></a><span class="lineno"> 33</span>  <span class="comment">// Returns the ceil (resp. floor) of the ratio of two integers.</span></div><div class="line"><a name="l00034"></a><span class="lineno"> 34</span>  <span class="comment">//</span></div><div class="line"><a name="l00035"></a><span class="lineno"> 35</span>  <span class="comment">// IntegralType: any integral type, whether signed or not.</span></div><div class="line"><a name="l00036"></a><span class="lineno"> 36</span>  <span class="comment">// numerator: any integer: positive, negative, or zero.</span></div><div class="line"><a name="l00037"></a><span class="lineno"> 37</span>  <span class="comment">// denominator: a non-zero integer, positive or negative.</span></div><div class="line"><a name="l00038"></a><span class="lineno"> 38</span>  <span class="keyword">template</span> <<span class="keyword">typename</span> IntegralType></div><div class="line"><a name="l00039"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_math_util.html#a0cfaf8b139304c54e3403d4ffbd60157"> 39</a></span>  <span class="keyword">static</span> IntegralType <a class="code" href="classoperations__research_1_1_math_util.html#a0cfaf8b139304c54e3403d4ffbd60157">CeilOfRatio</a>(IntegralType numerator,</div><div class="line"><a name="l00040"></a><span class="lineno"> 40</span>  IntegralType denominator) {</div><div class="line"><a name="l00041"></a><span class="lineno"> 41</span>  <a class="code" href="base_2logging_8h.html#a46e69120fbd3b36e6960e096d23b66f0">DCHECK_NE</a>(0, denominator);</div><div class="line"><a name="l00042"></a><span class="lineno"> 42</span>  <span class="keyword">const</span> IntegralType rounded_toward_zero = numerator / denominator;</div><div class="line"><a name="l00043"></a><span class="lineno"> 43</span>  <span class="keyword">const</span> IntegralType intermediate_product = rounded_toward_zero * denominator;</div><div class="line"><a name="l00044"></a><span class="lineno"> 44</span>  <span class="keyword">const</span> <span class="keywordtype">bool</span> needs_adjustment =</div><div class="line"><a name="l00045"></a><span class="lineno"> 45</span>  (rounded_toward_zero >= 0) &&</div><div class="line"><a name="l00046"></a><span class="lineno"> 46</span>  ((denominator > 0 && numerator > intermediate_product) ||</div><div class="line"><a name="l00047"></a><span class="lineno"> 47</span>  (denominator < 0 && numerator < intermediate_product));</div><div class="line"><a name="l00048"></a><span class="lineno"> 48</span>  <span class="keyword">const</span> IntegralType adjustment = static_cast<IntegralType>(needs_adjustment);</div><div class="line"><a name="l00049"></a><span class="lineno"> 49</span>  <span class="keyword">const</span> IntegralType ceil_of_ratio = rounded_toward_zero + adjustment;</div><div class="line"><a name="l00050"></a><span class="lineno"> 50</span>  <span class="keywordflow">return</span> ceil_of_ratio;</div><div class="line"><a name="l00051"></a><span class="lineno"> 51</span>  }</div><div class="line"><a name="l00052"></a><span class="lineno"> 52</span>  <span class="keyword">template</span> <<span class="keyword">typename</span> IntegralType></div><div class="line"><a name="l00053"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_math_util.html#a9e5c13b72c36481ed098c05031d1f850"> 53</a></span>  <span class="keyword">static</span> IntegralType <a class="code" href="classoperations__research_1_1_math_util.html#a9e5c13b72c36481ed098c05031d1f850">FloorOfRatio</a>(IntegralType numerator,</div><div class="line"><a name="l00054"></a><span class="lineno"> 54</span>  IntegralType denominator) {</div><div class="line"><a name="l00055"></a><span class="lineno"> 55</span>  <a class="code" href="base_2logging_8h.html#a46e69120fbd3b36e6960e096d23b66f0">DCHECK_NE</a>(0, denominator);</div><div class="line"><a name="l00056"></a><span class="lineno"> 56</span>  <span class="keyword">const</span> IntegralType rounded_toward_zero = numerator / denominator;</div><div class="line"><a name="l00057"></a><span class="lineno"> 57</span>  <span class="keyword">const</span> IntegralType intermediate_product = rounded_toward_zero * denominator;</div><div class="line"><a name="l00058"></a><span class="lineno"> 58</span>  <span class="keyword">const</span> <span class="keywordtype">bool</span> needs_adjustment =</div><div class="line"><a name="l00059"></a><span class="lineno"> 59</span>  (rounded_toward_zero <= 0) &&</div><div class="line"><a name="l00060"></a><span class="lineno"> 60</span>  ((denominator > 0 && numerator < intermediate_product) ||</div><div class="line"><a name="l00061"></a><span class="lineno"> 61</span>  (denominator < 0 && numerator > intermediate_product));</div><div class="line"><a name="l00062"></a><span class="lineno"> 62</span>  <span class="keyword">const</span> IntegralType adjustment = static_cast<IntegralType>(needs_adjustment);</div><div class="line"><a name="l00063"></a><span class="lineno"> 63</span>  <span class="keyword">const</span> IntegralType floor_of_ratio = rounded_toward_zero - adjustment;</div><div class="line"><a name="l00064"></a><span class="lineno"> 64</span>  <span class="keywordflow">return</span> floor_of_ratio;</div><div class="line"><a name="l00065"></a><span class="lineno"> 65</span>  }</div><div class="line"><a name="l00066"></a><span class="lineno"> 66</span> </div><div class="line"><a name="l00067"></a><span class="lineno"> 67</span>  <span class="comment">// Returns the greatest common divisor of two unsigned integers x and y.</span></div><div class="line"><a name="l00068"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_math_util.html#a5677e679e0d095f4cfb0a61d213ccdd7"> 68</a></span>  <span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="classoperations__research_1_1_math_util.html#a5677e679e0d095f4cfb0a61d213ccdd7">GCD</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> x, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> y) {</div><div class="line"><a name="l00069"></a><span class="lineno"> 69</span>  <span class="keywordflow">while</span> (y != 0) {</div><div class="line"><a name="l00070"></a><span class="lineno"> 70</span>  <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> r = x % y;</div><div class="line"><a name="l00071"></a><span class="lineno"> 71</span>  x = y;</div><div class="line"><a name="l00072"></a><span class="lineno"> 72</span>  y = r;</div><div class="line"><a name="l00073"></a><span class="lineno"> 73</span>  }</div><div class="line"><a name="l00074"></a><span class="lineno"> 74</span>  <span class="keywordflow">return</span> x;</div><div class="line"><a name="l00075"></a><span class="lineno"> 75</span>  }</div><div class="line"><a name="l00076"></a><span class="lineno"> 76</span> </div><div class="line"><a name="l00077"></a><span class="lineno"> 77</span>  <span class="comment">// Returns the least common multiple of two unsigned integers. Returns zero</span></div><div class="line"><a name="l00078"></a><span class="lineno"> 78</span>  <span class="comment">// if either is zero.</span></div><div class="line"><a name="l00079"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_math_util.html#abbe5e5d1b78a1362e85ed75e3a8f49c5"> 79</a></span>  <span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="classoperations__research_1_1_math_util.html#abbe5e5d1b78a1362e85ed75e3a8f49c5">LeastCommonMultiple</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="constraint__solver_2table_8cc.html#acb18315d548212835cd8ed4287e6c0b6">a</a>, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="constraint__solver_2table_8cc.html#a9293e4d29cac928301645070dd307683">b</a>) {</div><div class="line"><a name="l00080"></a><span class="lineno"> 80</span>  <span class="keywordflow">if</span> (<a class="code" href="constraint__solver_2table_8cc.html#acb18315d548212835cd8ed4287e6c0b6">a</a> > <a class="code" href="constraint__solver_2table_8cc.html#a9293e4d29cac928301645070dd307683">b</a>) {</div><div class="line"><a name="l00081"></a><span class="lineno"> 81</span>  <span class="keywordflow">return</span> (<a class="code" href="constraint__solver_2table_8cc.html#acb18315d548212835cd8ed4287e6c0b6">a</a> / <a class="code" href="classoperations__research_1_1_math_util.html#a5677e679e0d095f4cfb0a61d213ccdd7">MathUtil::GCD</a>(<a class="code" href="constraint__solver_2table_8cc.html#acb18315d548212835cd8ed4287e6c0b6">a</a>, <a class="code" href="constraint__solver_2table_8cc.html#a9293e4d29cac928301645070dd307683">b</a>)) * <a class="code" href="constraint__solver_2table_8cc.html#a9293e4d29cac928301645070dd307683">b</a>;</div><div class="line"><a name="l00082"></a><span class="lineno"> 82</span>  } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="constraint__solver_2table_8cc.html#acb18315d548212835cd8ed4287e6c0b6">a</a> < <a class="code" href="constraint__solver_2table_8cc.html#a9293e4d29cac928301645070dd307683">b</a>) {</div><div class="line"><a name="l00083"></a><span class="lineno"> 83</span>  <span class="keywordflow">return</span> (<a class="code" href="constraint__solver_2table_8cc.html#a9293e4d29cac928301645070dd307683">b</a> / <a class="code" href="classoperations__research_1_1_math_util.html#a5677e679e0d095f4cfb0a61d213ccdd7">MathUtil::GCD</a>(<a class="code" href="constraint__solver_2table_8cc.html#a9293e4d29cac928301645070dd307683">b</a>, <a class="code" href="constraint__solver_2table_8cc.html#acb18315d548212835cd8ed4287e6c0b6">a</a>)) * <a class="code" href="constraint__solver_2table_8cc.html#acb18315d548212835cd8ed4287e6c0b6">a</a>;</div><div class="line"><a name="l00084"></a><span class="lineno"> 84</span>  } <span class="keywordflow">else</span> {</div><div class="line"><a name="l00085"></a><span class="lineno"> 85</span>  <span class="keywordflow">return</span> <a class="code" href="constraint__solver_2table_8cc.html#acb18315d548212835cd8ed4287e6c0b6">a</a>;</div><div class="line"><a name="l00086"></a><span class="lineno"> 86</span>  }</div><div class="line"><a name="l00087"></a><span class="lineno"> 87</span>  }</div><div class="line"><a name="l00088"></a><span class="lineno"> 88</span> </div><div class="line"><a name="l00089"></a><span class="lineno"> 89</span>  <span class="comment">// Absolute value of x.</span></div><div class="line"><a name="l00090"></a><span class="lineno"> 90</span>  <span class="comment">// Works correctly for unsigned types and</span></div><div class="line"><a name="l00091"></a><span class="lineno"> 91</span>  <span class="comment">// for special floating point values.</span></div><div class="line"><a name="l00092"></a><span class="lineno"> 92</span>  <span class="comment">// Note: 0.0 and -0.0 are not differentiated by Abs (Abs(0.0) is -0.0),</span></div><div class="line"><a name="l00093"></a><span class="lineno"> 93</span>  <span class="comment">// which should be OK: see the comment for Max above.</span></div><div class="line"><a name="l00094"></a><span class="lineno"> 94</span>  <span class="keyword">template</span> <<span class="keyword">typename</span> T></div><div class="line"><a name="l00095"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_math_util.html#a5a6f14696b2a09c97b58e4f0989b19e7"> 95</a></span>  <span class="keyword">static</span> T <a class="code" href="classoperations__research_1_1_math_util.html#a5a6f14696b2a09c97b58e4f0989b19e7">Abs</a>(<span class="keyword">const</span> T x) {</div><div class="line"><a name="l00096"></a><span class="lineno"> 96</span>  <span class="keywordflow">return</span> x > 0 ? x : -x;</div><div class="line"><a name="l00097"></a><span class="lineno"> 97</span>  }</div><div class="line"><a name="l00098"></a><span class="lineno"> 98</span> </div><div class="line"><a name="l00099"></a><span class="lineno"> 99</span>  <span class="comment">// Returns the square of x.</span></div><div class="line"><a name="l00100"></a><span class="lineno"> 100</span>  <span class="keyword">template</span> <<span class="keyword">typename</span> T></div><div class="line"><a name="l00101"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_math_util.html#aac72849250cdf23aefdd991eb0fc0385"> 101</a></span>  <span class="keyword">static</span> T <a class="code" href="classoperations__research_1_1_math_util.html#aac72849250cdf23aefdd991eb0fc0385">Square</a>(<span class="keyword">const</span> T x) {</div><div class="line"><a name="l00102"></a><span class="lineno"> 102</span>  <span class="keywordflow">return</span> x * x;</div><div class="line"><a name="l00103"></a><span class="lineno"> 103</span>  }</div><div class="line"><a name="l00104"></a><span class="lineno"> 104</span> </div><div class="line"><a name="l00105"></a><span class="lineno"> 105</span>  <span class="comment">// Euclid's Algorithm.</span></div><div class="line"><a name="l00106"></a><span class="lineno"> 106</span>  <span class="comment">// Returns: the greatest common divisor of two unsigned integers x and y.</span></div><div class="line"><a name="l00107"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_math_util.html#ae94db7b2fa1d8e1b3c1dc6c683191609"> 107</a></span>  <span class="keyword">static</span> int64_t <a class="code" href="classoperations__research_1_1_math_util.html#ae94db7b2fa1d8e1b3c1dc6c683191609">GCD64</a>(int64_t x, int64_t y) {</div><div class="line"><a name="l00108"></a><span class="lineno"> 108</span>  <a class="code" href="base_2logging_8h.html#aae2dc65d9ea248d54bf39daa986dd295">DCHECK_GE</a>(x, 0);</div><div class="line"><a name="l00109"></a><span class="lineno"> 109</span>  <a class="code" href="base_2logging_8h.html#aae2dc65d9ea248d54bf39daa986dd295">DCHECK_GE</a>(y, 0);</div><div class="line"><a name="l00110"></a><span class="lineno"> 110</span>  <span class="keywordflow">while</span> (y != 0) {</div><div class="line"><a name="l00111"></a><span class="lineno"> 111</span>  int64_t r = x % y;</div><div class="line"><a name="l00112"></a><span class="lineno"> 112</span>  x = y;</div><div class="line"><a name="l00113"></a><span class="lineno"> 113</span>  y = r;</div><div class="line"><a name="l00114"></a><span class="lineno"> 114</span>  }</div><div class="line"><a name="l00115"></a><span class="lineno"> 115</span>  <span class="keywordflow">return</span> x;</div><div class="line"><a name="l00116"></a><span class="lineno"> 116</span>  }</div><div class="line"><a name="l00117"></a><span class="lineno"> 117</span> </div><div class="line"><a name="l00118"></a><span class="lineno"> 118</span>  <span class="keyword">template</span> <<span class="keyword">typename</span> T></div><div class="line"><a name="l00119"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_math_util.html#a622bd31ec5ba0613cc927849af4138ee"> 119</a></span>  <span class="keyword">static</span> T <a class="code" href="classoperations__research_1_1_math_util.html#a622bd31ec5ba0613cc927849af4138ee">IPow</a>(T base, <span class="keywordtype">int</span> exp) {</div><div class="line"><a name="l00120"></a><span class="lineno"> 120</span>  <span class="keywordflow">return</span> pow(base, exp);</div><div class="line"><a name="l00121"></a><span class="lineno"> 121</span>  }</div><div class="line"><a name="l00122"></a><span class="lineno"> 122</span> </div><div class="line"><a name="l00123"></a><span class="lineno"> 123</span>  <span class="keyword">template</span> <<span class="keyword">class</span> IntOut, <span class="keyword">class</span> FloatIn></div><div class="line"><a name="l00124"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_math_util.html#aad6225dda2c124a0e6acdc496d306f41"> 124</a></span>  <span class="keyword">static</span> IntOut <a class="code" href="classoperations__research_1_1_math_util.html#aad6225dda2c124a0e6acdc496d306f41">Round</a>(FloatIn x) {</div><div class="line"><a name="l00125"></a><span class="lineno"> 125</span>  <span class="comment">// We don't use sgn(x) below because there is no need to distinguish the</span></div><div class="line"><a name="l00126"></a><span class="lineno"> 126</span>  <span class="comment">// (x == 0) case. Also note that there are specialized faster versions</span></div><div class="line"><a name="l00127"></a><span class="lineno"> 127</span>  <span class="comment">// of this function for Intel, ARM and PPC processors at the bottom</span></div><div class="line"><a name="l00128"></a><span class="lineno"> 128</span>  <span class="comment">// of this file.</span></div><div class="line"><a name="l00129"></a><span class="lineno"> 129</span>  <span class="keywordflow">if</span> (x > -0.5 && x < 0.5) {</div><div class="line"><a name="l00130"></a><span class="lineno"> 130</span>  <span class="comment">// This case is special, because for largest floating point number</span></div><div class="line"><a name="l00131"></a><span class="lineno"> 131</span>  <span class="comment">// below 0.5, the addition of 0.5 yields 1 and this would lead</span></div><div class="line"><a name="l00132"></a><span class="lineno"> 132</span>  <span class="comment">// to incorrect result.</span></div><div class="line"><a name="l00133"></a><span class="lineno"> 133</span>  <span class="keywordflow">return</span> static_cast<IntOut>(0);</div><div class="line"><a name="l00134"></a><span class="lineno"> 134</span>  }</div><div class="line"><a name="l00135"></a><span class="lineno"> 135</span>  <span class="keywordflow">return</span> static_cast<IntOut>(x < 0 ? (x - 0.5) : (x + 0.5));</div><div class="line"><a name="l00136"></a><span class="lineno"> 136</span>  }</div><div class="line"><a name="l00137"></a><span class="lineno"> 137</span> </div><div class="line"><a name="l00138"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_math_util.html#a55fc8a3af7c2526c83e83586cd578d89"> 138</a></span>  <span class="keyword">static</span> int64_t <a class="code" href="classoperations__research_1_1_math_util.html#a55fc8a3af7c2526c83e83586cd578d89">FastInt64Round</a>(<span class="keywordtype">double</span> x) { <span class="keywordflow">return</span> Round<int64_t>(x); }</div><div class="line"><a name="l00139"></a><span class="lineno"> 139</span> };</div><div class="line"><a name="l00140"></a><span class="lineno"> 140</span> } <span class="comment">// namespace operations_research</span></div><div class="line"><a name="l00141"></a><span class="lineno"> 141</span> </div><div class="line"><a name="l00142"></a><span class="lineno"> 142</span> <span class="preprocessor">#endif // OR_TOOLS_BASE_MATHUTIL_H_</span></div><div class="ttc" id="classoperations__research_1_1_math_util_html_aad6225dda2c124a0e6acdc496d306f41"><div class="ttname"><a href="classoperations__research_1_1_math_util.html#aad6225dda2c124a0e6acdc496d306f41">operations_research::MathUtil::Round</a></div><div class="ttdeci">static IntOut Round(FloatIn x)</div><div class="ttdef"><b>Definition:</b> <a href="mathutil_8h_source.html#l00124">mathutil.h:124</a></div></div>
|
|
<div class="ttc" id="classoperations__research_1_1_math_util_html_abbe5e5d1b78a1362e85ed75e3a8f49c5"><div class="ttname"><a href="classoperations__research_1_1_math_util.html#abbe5e5d1b78a1362e85ed75e3a8f49c5">operations_research::MathUtil::LeastCommonMultiple</a></div><div class="ttdeci">static unsigned int LeastCommonMultiple(unsigned int a, unsigned int b)</div><div class="ttdef"><b>Definition:</b> <a href="mathutil_8h_source.html#l00079">mathutil.h:79</a></div></div>
|
|
<div class="ttc" id="classoperations__research_1_1_math_util_html_a55fc8a3af7c2526c83e83586cd578d89"><div class="ttname"><a href="classoperations__research_1_1_math_util.html#a55fc8a3af7c2526c83e83586cd578d89">operations_research::MathUtil::FastInt64Round</a></div><div class="ttdeci">static int64_t FastInt64Round(double x)</div><div class="ttdef"><b>Definition:</b> <a href="mathutil_8h_source.html#l00138">mathutil.h:138</a></div></div>
|
|
<div class="ttc" id="classoperations__research_1_1_math_util_html_a0cfaf8b139304c54e3403d4ffbd60157"><div class="ttname"><a href="classoperations__research_1_1_math_util.html#a0cfaf8b139304c54e3403d4ffbd60157">operations_research::MathUtil::CeilOfRatio</a></div><div class="ttdeci">static IntegralType CeilOfRatio(IntegralType numerator, IntegralType denominator)</div><div class="ttdef"><b>Definition:</b> <a href="mathutil_8h_source.html#l00039">mathutil.h:39</a></div></div>
|
|
<div class="ttc" id="constraint__solver_2table_8cc_html_a9293e4d29cac928301645070dd307683"><div class="ttname"><a href="constraint__solver_2table_8cc.html#a9293e4d29cac928301645070dd307683">b</a></div><div class="ttdeci">int64_t b</div><div class="ttdef"><b>Definition:</b> <a href="constraint__solver_2table_8cc_source.html#l00047">constraint_solver/table.cc:47</a></div></div>
|
|
<div class="ttc" id="integral__types_8h_html"><div class="ttname"><a href="integral__types_8h.html">integral_types.h</a></div></div>
|
|
<div class="ttc" id="macros_8h_html"><div class="ttname"><a href="macros_8h.html">macros.h</a></div></div>
|
|
<div class="ttc" id="base_2logging_8h_html_a46e69120fbd3b36e6960e096d23b66f0"><div class="ttname"><a href="base_2logging_8h.html#a46e69120fbd3b36e6960e096d23b66f0">DCHECK_NE</a></div><div class="ttdeci">#define DCHECK_NE(val1, val2)</div><div class="ttdef"><b>Definition:</b> <a href="base_2logging_8h_source.html#l00891">base/logging.h:891</a></div></div>
|
|
<div class="ttc" id="classoperations__research_1_1_math_util_html_a5a6f14696b2a09c97b58e4f0989b19e7"><div class="ttname"><a href="classoperations__research_1_1_math_util.html#a5a6f14696b2a09c97b58e4f0989b19e7">operations_research::MathUtil::Abs</a></div><div class="ttdeci">static T Abs(const T x)</div><div class="ttdef"><b>Definition:</b> <a href="mathutil_8h_source.html#l00095">mathutil.h:95</a></div></div>
|
|
<div class="ttc" id="classoperations__research_1_1_math_util_html_aac72849250cdf23aefdd991eb0fc0385"><div class="ttname"><a href="classoperations__research_1_1_math_util.html#aac72849250cdf23aefdd991eb0fc0385">operations_research::MathUtil::Square</a></div><div class="ttdeci">static T Square(const T x)</div><div class="ttdef"><b>Definition:</b> <a href="mathutil_8h_source.html#l00101">mathutil.h:101</a></div></div>
|
|
<div class="ttc" id="classoperations__research_1_1_math_util_html_ae94db7b2fa1d8e1b3c1dc6c683191609"><div class="ttname"><a href="classoperations__research_1_1_math_util.html#ae94db7b2fa1d8e1b3c1dc6c683191609">operations_research::MathUtil::GCD64</a></div><div class="ttdeci">static int64_t GCD64(int64_t x, int64_t y)</div><div class="ttdef"><b>Definition:</b> <a href="mathutil_8h_source.html#l00107">mathutil.h:107</a></div></div>
|
|
<div class="ttc" id="classoperations__research_1_1_math_util_html_a9e5c13b72c36481ed098c05031d1f850"><div class="ttname"><a href="classoperations__research_1_1_math_util.html#a9e5c13b72c36481ed098c05031d1f850">operations_research::MathUtil::FloorOfRatio</a></div><div class="ttdeci">static IntegralType FloorOfRatio(IntegralType numerator, IntegralType denominator)</div><div class="ttdef"><b>Definition:</b> <a href="mathutil_8h_source.html#l00053">mathutil.h:53</a></div></div>
|
|
<div class="ttc" id="base_2logging_8h_html_aae2dc65d9ea248d54bf39daa986dd295"><div class="ttname"><a href="base_2logging_8h.html#aae2dc65d9ea248d54bf39daa986dd295">DCHECK_GE</a></div><div class="ttdeci">#define DCHECK_GE(val1, val2)</div><div class="ttdef"><b>Definition:</b> <a href="base_2logging_8h_source.html#l00894">base/logging.h:894</a></div></div>
|
|
<div class="ttc" id="base_2logging_8h_html"><div class="ttname"><a href="base_2logging_8h.html">logging.h</a></div></div>
|
|
<div class="ttc" id="classoperations__research_1_1_math_util_html"><div class="ttname"><a href="classoperations__research_1_1_math_util.html">operations_research::MathUtil</a></div><div class="ttdef"><b>Definition:</b> <a href="mathutil_8h_source.html#l00029">mathutil.h:29</a></div></div>
|
|
<div class="ttc" id="namespaceoperations__research_html"><div class="ttname"><a href="namespaceoperations__research.html">operations_research</a></div><div class="ttdoc">Collection of objects used to extend the Constraint Solver library.</div><div class="ttdef"><b>Definition:</b> <a href="dense__doubly__linked__list_8h_source.html#l00021">dense_doubly_linked_list.h:21</a></div></div>
|
|
<div class="ttc" id="classoperations__research_1_1_math_util_html_a622bd31ec5ba0613cc927849af4138ee"><div class="ttname"><a href="classoperations__research_1_1_math_util.html#a622bd31ec5ba0613cc927849af4138ee">operations_research::MathUtil::IPow</a></div><div class="ttdeci">static T IPow(T base, int exp)</div><div class="ttdef"><b>Definition:</b> <a href="mathutil_8h_source.html#l00119">mathutil.h:119</a></div></div>
|
|
<div class="ttc" id="basictypes_8h_html"><div class="ttname"><a href="basictypes_8h.html">basictypes.h</a></div></div>
|
|
<div class="ttc" id="classoperations__research_1_1_math_util_html_a5677e679e0d095f4cfb0a61d213ccdd7"><div class="ttname"><a href="classoperations__research_1_1_math_util.html#a5677e679e0d095f4cfb0a61d213ccdd7">operations_research::MathUtil::GCD</a></div><div class="ttdeci">static unsigned int GCD(unsigned int x, unsigned int y)</div><div class="ttdef"><b>Definition:</b> <a href="mathutil_8h_source.html#l00068">mathutil.h:68</a></div></div>
|
|
<div class="ttc" id="constraint__solver_2table_8cc_html_acb18315d548212835cd8ed4287e6c0b6"><div class="ttname"><a href="constraint__solver_2table_8cc.html#acb18315d548212835cd8ed4287e6c0b6">a</a></div><div class="ttdeci">int64_t a</div><div class="ttdef"><b>Definition:</b> <a href="constraint__solver_2table_8cc_source.html#l00046">constraint_solver/table.cc:46</a></div></div>
|
|
</div><!-- fragment --></div><!-- contents -->
|
|
</div><!-- doc-content -->
|
|
<!-- HTML footer for doxygen 1.8.18-->
|
|
<!-- start footer part -->
|
|
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
|
|
<ul>
|
|
<li class="navelem"><a class="el" href="dir_a7cc1eeded8f693d0da6c729bc88c45a.html">ortools</a></li><li class="navelem"><a class="el" href="dir_8f9dc966244f4c6e9b2fa0dee1e4ef1a.html">base</a></li><li class="navelem"><a class="el" href="mathutil_8h.html">mathutil.h</a></li>
|
|
<li class="footer">Generated by
|
|
<a href="http://www.doxygen.org/index.html">
|
|
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.15 </li>
|
|
</ul>
|
|
</div>
|
|
</body>
|
|
</html>
|