scfx_pow10.cpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002 
00003   The following code is derived, directly or indirectly, from the SystemC
00004   source code Copyright (c) 1996-2006 by all Contributors.
00005   All Rights reserved.
00006 
00007   The contents of this file are subject to the restrictions and limitations
00008   set forth in the SystemC Open Source License Version 2.4 (the "License");
00009   You may not use this file except in compliance with such restrictions and
00010   limitations. You may obtain instructions on how to receive a copy of the
00011   License at http://www.systemc.org/. Software distributed by Contributors
00012   under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
00013   ANY KIND, either express or implied. See the License for the specific
00014   language governing rights and limitations under the License.
00015 
00016  *****************************************************************************/
00017 
00018 /*****************************************************************************
00019 
00020   scfx_pow10.cpp - 
00021 
00022   Original Author: Robert Graulich, Synopsys, Inc.
00023                    Martin Janssen,  Synopsys, Inc.
00024 
00025  *****************************************************************************/
00026 
00027 /*****************************************************************************
00028 
00029   MODIFICATION LOG - modifiers, enter your name, affiliation, date and
00030   changes you are making here.
00031 
00032       Name, Affiliation, Date:
00033   Description of Modification:
00034 
00035  *****************************************************************************/
00036 
00037 
00038 // $Log: scfx_pow10.cpp,v $
00039 // Revision 1.1.1.1  2006/12/15 20:31:36  acg
00040 // SystemC 2.2
00041 //
00042 // Revision 1.3  2006/01/13 18:53:58  acg
00043 // Andy Goodrich: added $Log command so that CVS comments are reproduced in
00044 // the source.
00045 //
00046 
00047 #include "sysc/datatypes/fx/scfx_pow10.h"
00048 
00049 
00050 namespace sc_dt
00051 {
00052 
00053 // ----------------------------------------------------------------------------
00054 //  CLASS : scfx_pow10
00055 //
00056 //  Class to compute (and cache) powers of 10 in arbitrary precision.
00057 // ----------------------------------------------------------------------------
00058 
00059 scfx_pow10::scfx_pow10()
00060 {
00061     m_pos[0] = scfx_rep( 10.0 );
00062     m_neg[0] = scfx_rep( 0.1 );
00063 
00064     for( int i = 1; i < SCFX_POW10_TABLE_SIZE; i ++ )
00065     {
00066         m_pos[i].set_nan();
00067     m_neg[i].set_nan();
00068     }
00069 }
00070 
00071 scfx_pow10::~scfx_pow10()
00072 {}
00073 
00074 
00075 const scfx_rep
00076 scfx_pow10::operator() ( int i )
00077 {
00078     if( i == 0 ) {
00079         return scfx_rep( 1.0 );
00080     }
00081 
00082     if( i > 0 )
00083     {
00084         int bit = scfx_find_msb( i );
00085     scfx_rep result = *pos( bit );
00086     if( bit )
00087     {
00088         while( -- bit >= 0 )
00089         {
00090             if( ( 1 << bit ) & i )
00091         {
00092             scfx_rep* tmp = mult_scfx_rep( result, *pos( bit ) );
00093             result = *tmp;
00094             delete tmp;
00095         }
00096         }
00097     }
00098     return result;
00099     }
00100     else
00101     {
00102         i = -i;
00103     int bit = scfx_find_msb( i );
00104     scfx_rep result = *neg( bit );
00105     if( bit )
00106     {
00107         while( -- bit >= 0 )
00108         {
00109             if( ( 1 << bit ) & i )
00110         {
00111             scfx_rep* tmp = mult_scfx_rep( result, *neg( bit ) );
00112             result = *tmp;
00113             delete tmp;
00114         }
00115         }
00116     }
00117     return result;
00118     }
00119 }
00120 
00121 
00122 scfx_rep*
00123 scfx_pow10::pos( int i )
00124 {
00125     if( ! m_pos[i].is_normal() )
00126     {
00127         multiply( m_pos[i], *pos( i - 1 ), *pos( i - 1 ) );
00128     }
00129     return &m_pos[i];
00130 }
00131 
00132 scfx_rep*
00133 scfx_pow10::neg( int i )
00134 {
00135     if( ! m_neg[i].is_normal() )
00136     {
00137     multiply( m_neg[i], *neg( i - 1 ), *neg( i - 1 ) );
00138     }
00139     return &m_neg[i];
00140 }
00141 
00142 } // namespace sc_dt
00143 
00144 
00145 // Taf!

Generated on Wed Jan 21 15:32:08 2009 for SystemC by  doxygen 1.5.5