GiNaCRA  0.6.4
RealAlgebraicNumberNR.cpp
Go to the documentation of this file.
00001 /*
00002  * GiNaCRA - GiNaC Real Algebra package
00003  * Copyright (C) 2010-2012  Ulrich Loup, Joachim Redies, Sebastian Junges
00004  *
00005  * This file is part of GiNaCRA.
00006  *
00007  * GiNaCRA is free software: you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation, either version 3 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * GiNaCRA is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with GiNaCRA.  If not, see <http://www.gnu.org/licenses/>.
00019  *
00020  */
00021 
00022 
00034 #include "RealAlgebraicNumberNR.h"
00035 
00036 using GiNaC::ZERO_SIGN;
00037 using GiNaC::POSITIVE_SIGN;
00038 using GiNaC::NEGATIVE_SIGN;
00039 
00040 namespace GiNaCRA
00041 {
00043     // Con- and destructors //
00045 
00046     RealAlgebraicNumberNR::RealAlgebraicNumberNR( const numeric& n, bool isRoot ):
00047         RealAlgebraicNumber( isRoot, true, n ),
00048         numeric( n )
00049     {
00050         mValue = *this;
00051     }
00052 
00053     RealAlgebraicNumberNR::RealAlgebraicNumberNR( const RealAlgebraicNumberNR& n ):
00054         RealAlgebraicNumber( n.isRoot(), true, static_cast<numeric>(n) ),
00055         numeric( static_cast<numeric>(n) )
00056     {
00057         mValue = *this;
00058     }
00059 
00061     // Operations //
00063 
00064     GiNaC::sign RealAlgebraicNumberNR::sgn() const
00065     {
00066         if( *this == 0 )
00067             return ZERO_SIGN;
00068         else if( *this > 0 )
00069             return POSITIVE_SIGN;
00070         else
00071             return NEGATIVE_SIGN;
00072     }
00073 
00074     GiNaC::sign RealAlgebraicNumberNR::sgn( const RationalUnivariatePolynomial& p ) const
00075     {
00076         switch( p.sgn( *this ))
00077         {
00078             case 0:
00079                 return ZERO_SIGN;
00080             case 1:
00081                 return POSITIVE_SIGN;
00082             case -1:
00083                 return NEGATIVE_SIGN;
00084         }
00085         return NEGATIVE_SIGN;
00086     }
00087 
00089     // Methods from basic  //
00091 
00092     void RealAlgebraicNumberNR::do_print( const print_context& c, unsigned level ) const
00093     {
00094         numeric::do_print( c, level );
00095         c.s << (mIsRoot ? "~" : "");
00096     }
00097 
00098 }    // namespace GiNaC
00099