Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > ff8e7344076b5fbaa54d805766a057bd > files > 10

libscs-devel-1.4.1-4.fc15.i686.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>double2scs.c Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.2.15 -->
<center>
<a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="annotated.html">Data Structures</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Data Fields</a> &nbsp; <a class="qindex" href="globals.html">Globals</a> &nbsp; </center>
<hr><h1>double2scs.c</h1><a href="double2scs_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="comment">/** Conversion of floating-point double to SCS</font>
00002 <font class="comment">@file double2scs.c</font>
00003 <font class="comment"></font>
00004 <font class="comment">@author Defour David David.Defour@ens-lyon.fr</font>
00005 <font class="comment">@author Florent de Dinechin Florent.de.Dinechin@ens-lyon.fr </font>
00006 <font class="comment"></font>
00007 <font class="comment">This file is part of the SCS library.</font>
00008 <font class="comment">*/</font>
00009 
00010 <font class="comment">/*</font>
00011 <font class="comment">Copyright (C) 2002  David Defour and Florent de Dinechin</font>
00012 <font class="comment"></font>
00013 <font class="comment">    This library is free software; you can redistribute it and/or</font>
00014 <font class="comment">    modify it under the terms of the GNU Lesser General Public</font>
00015 <font class="comment">    License as published by the Free Software Foundation; either</font>
00016 <font class="comment">    version 2.1 of the License, or (at your option) any later version.</font>
00017 <font class="comment"></font>
00018 <font class="comment">    This library is distributed in the hope that it will be useful,</font>
00019 <font class="comment">    but WITHOUT ANY WARRANTY; without even the implied warranty of</font>
00020 <font class="comment">    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</font>
00021 <font class="comment">    Lesser General Public License for more details.</font>
00022 <font class="comment"></font>
00023 <font class="comment">    You should have received a copy of the GNU Lesser General Public</font>
00024 <font class="comment">    License along with this library; if not, write to the Free Software</font>
00025 <font class="comment">    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</font>
00026 <font class="comment"></font>
00027 <font class="comment"> */</font>
00028 <font class="preprocessor">#include "<a class="code" href="scs_8h.html">scs.h</a>"</font>
00029 <font class="preprocessor">#include "<a class="code" href="scs__private_8h.html">scs_private.h</a>"</font>
00030 
00031 <font class="comment"></font>
00032 <font class="comment">/** Convert a double precision number in it SCS multiprecision</font>
00033 <font class="comment">  representation</font>
00034 <font class="comment"> */</font>
00035 
<a name="l00036"></a><a class="code" href="double2scs_8c.html#a0">00036</a> <font class="keywordtype">void</font> <a class="code" href="double2scs_8c.html#a0">scs_set_d</a>(<a class="code" href="structscs.html">scs_ptr</a> result, <font class="keywordtype">double</font> x){
00037   scs_db_number nb, mantissa;
00038   <font class="keywordtype">int</font> exponent, exponent_remainder;
00039   <font class="keywordtype">int</font> ind, i;
00040 
00041   <font class="keywordflow">if</font>(x&gt;=0){R_SGN = 1;    nb.d = x;}
00042   <font class="keywordflow">else</font>    {R_SGN = -1;   nb.d = -x;}
00043 
00044   exponent = nb.i[HI_ENDIAN] &amp; 0x7ff00000 ;
00045 
00046   <font class="keywordflow">if</font> (exponent == 0x7ff00000)  {
00047     <font class="comment">/*</font>
00048 <font class="comment">     * x = +/- Inf, s/qNAN</font>
00049 <font class="comment">     */</font>
00050     R_EXP = x;  
00051     <font class="keywordflow">for</font>(i=0; i&lt;SCS_NB_WORDS; i++)
00052       R_HW[i] = 0;
00053  
00054     R_IND = 0;
00055     R_SGN = 1;
00056   } 
00057 
00058   <font class="keywordflow">else</font> {    <font class="comment">/* Normals,  denormals, +/- 0.  */</font>
00059 
00060     <font class="comment">/* This number is not an exception */</font>
00061     R_EXP = 1;
00062 
00063 <font class="preprocessor">#if 1</font>
00064 <font class="preprocessor"></font>
00065     <font class="keywordflow">if</font> (exponent == 0){
00066       <font class="comment">/* x is a denormal number : bring it back to the normal range */</font>
00067       nb.d = nb.d * SCS_RADIX_TWO_DOUBLE;      <font class="comment">/* 2^(2.SCS_NB_BITS) */</font>
00068       exponent = nb.i[HI_ENDIAN] &amp; 0x7ff00000 ;
00069       R_IND = -2;
00070     }<font class="keywordflow">else</font> {
00071       R_IND = 0;
00072     }
00073 
00074     exponent = exponent &gt;&gt; 20;  <font class="comment">/* get the actual value */</font>
00075 
00076     ind = ((exponent +((100*SCS_NB_BITS)-1023))/SCS_NB_BITS) - 100 ;  
00077     <font class="comment">/* means : = (exponent -1023 + 100*SCS_NB_BITS)/SCS_NB_BITS -100 </font>
00078 <font class="comment">     The business with 100*SCS_NB_BITS is to stay within the positive</font>
00079 <font class="comment">     range for exponent_remainder between 1 and SCS_NB_BITS */</font>
00080 
00081     exponent_remainder = exponent - 1022 - (SCS_NB_BITS*ind);
00082 
00083     R_IND += ind;
00084 
00085     <font class="comment">/* now get the mantissa and add the implicit 1 in fp. format*/</font>
00086     mantissa.l = (nb.l &amp; 0x000fffffffffffff) | 0x0010000000000000;
00087 
00088 
00089     <font class="comment">/* and spread it over the structure</font>
00090 <font class="comment">       Everything here is 64-bit arithmetic */</font>
00091     R_HW[0] = mantissa.l &gt;&gt; (53 - exponent_remainder);
00092 
00093     <font class="comment">/* 11 = 64-53 */</font>
00094     mantissa.l =  (mantissa.l &lt;&lt; (exponent_remainder+11));
00095     R_HW[1] = (mantissa.i[HI_ENDIAN] &gt;&gt; (32 - SCS_NB_BITS))&amp; SCS_MASK_RADIX ;
00096     mantissa.l =  (mantissa.l &lt;&lt; SCS_NB_BITS);
00097     R_HW[2] = (mantissa.i[HI_ENDIAN] &gt;&gt; (32 - SCS_NB_BITS))&amp; SCS_MASK_RADIX ;
00098 <font class="preprocessor">#if SCS_NB_BITS &lt; 27</font>
00099 <font class="preprocessor"></font>    mantissa.l =  (mantissa.l &lt;&lt; SCS_NB_BITS);
00100     R_HW[3] = (mantissa.i[HI_ENDIAN] &gt;&gt; (32 - SCS_NB_BITS))&amp; SCS_MASK_RADIX ;
00101 <font class="preprocessor">#else</font>
00102 <font class="preprocessor"></font>    R_HW[3] = 0 ;
00103 <font class="preprocessor">#endif</font>
00104 <font class="preprocessor"></font>
00105 <font class="preprocessor">#if (SCS_NB_WORDS==8)</font>
00106 <font class="preprocessor"></font>      R_HW[4] = 0; R_HW[5] = 0; R_HW[6] = 0; R_HW[7] = 0;
00107 <font class="preprocessor">#else</font>
00108 <font class="preprocessor"></font>    <font class="keywordflow">for</font>(i=4; i&lt;SCS_NB_WORDS; i++)
00109       R_HW[i] = 0;
00110 <font class="preprocessor">#endif</font>
00111 <font class="preprocessor"></font>
00112 
00113 
00114 <font class="preprocessor">#else </font><font class="comment">/* Other algorithm as in the research report. Slower */</font>
00115     R_IND = 0;
00116 
00117     <font class="keywordflow">while</font>(nb.d&gt;SCS_RADIX_ONE_DOUBLE) {
00118         R_IND++;
00119         nb.d *= SCS_RADIX_MONE_DOUBLE;
00120       }
00121 
00122     <font class="keywordflow">while</font>(nb.d&lt;1)  {
00123         R_IND--;
00124         nb.d *= SCS_RADIX_ONE_DOUBLE;
00125       }
00126 
00127     i=0;
00128     <font class="keywordflow">while</font>(nb.d != 0){
00129       R_HW[i] = (<font class="keywordtype">unsigned</font> <font class="keywordtype">int</font>) nb.d;
00130       nb.d = (nb.d - (double)R_HW[i]) * SCS_RADIX_ONE_DOUBLE;
00131       i++;
00132     }
00133     <font class="keywordflow">for</font>(; i&lt;SCS_NB_WORDS; i++)
00134       R_HW[i] = 0;
00135 
00136 <font class="preprocessor">#endif</font>
00137 <font class="preprocessor"></font>
00138   } <font class="comment">/* end if test NaN etc */</font>
00139 
00140   <font class="keywordflow">return</font>;
00141 }
00142 
00143 <font class="comment"></font>
00144 <font class="comment">/**</font>
00145 <font class="comment">  Convert an integer number in it scs multiprecision</font>
00146 <font class="comment">  representation</font>
00147 <font class="comment"> */</font>
<a name="l00148"></a><a class="code" href="double2scs_8c.html#a1">00148</a> <font class="keywordtype">void</font> <a class="code" href="double2scs_8c.html#a1">scs_set_si</a>(<a class="code" href="structscs.html">scs_ptr</a> result, <font class="keywordtype">signed</font> <font class="keywordtype">int</font> x){
00149   <font class="keywordtype">unsigned</font> <font class="keywordtype">int</font> ux;
00150   <font class="keywordtype">int</font> i;
00151   
00152   <font class="keywordflow">if</font>(x&gt;=0){R_SGN = 1;   ux = x;}
00153   <font class="keywordflow">else</font>    {R_SGN = -1;  ux = -x;}
00154   
00155 
00156   <font class="keywordflow">if</font> (ux &gt; SCS_RADIX){
00157     R_IND   = 1;
00158     R_HW[0] = (ux - SCS_RADIX) &gt;&gt; SCS_NB_BITS;
00159     R_HW[1] =  ux - (R_HW[0] &lt;&lt; SCS_NB_BITS);
00160   }<font class="keywordflow">else</font> {
00161     R_IND   = 0;
00162     R_HW[0] = ux;
00163     R_HW[1] = 0;
00164   }
00165 
00166   <font class="keywordflow">for</font>(i=2; i&lt;SCS_NB_WORDS; i++)
00167     R_HW[i] = 0;
00168 
00169   <font class="keywordflow">if</font> (x != 0)  R_EXP = 1;
00170   <font class="keywordflow">else</font>         R_EXP = 0;
00171   
00172   <font class="keywordflow">return</font>;
00173 }
00174 
</pre></div><hr><address align="right"><small>Generated on Tue Jun 17 10:15:51 2003 for SCSLib by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0 
width=110 height=53></a>1.2.15 </small></address>
</body>
</html>