Changeset fc732a9 in git for factory/int_int.h


Ignore:
Timestamp:
Mar 17, 1998, 4:59:42 PM (26 years ago)
Author:
Jens Schmidt <schmidt@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
e0fb8d31ff69374db7f865baedfda3e614804382
Parents:
bb17e813fdec9082fa78763093e18795ea0fdbb4
Message:
***** merge from branch `factory-gcd' to main trunk


git-svn-id: file:///usr/local/Singular/svn/trunk@1251 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • factory/int_int.h

    rbb17e8 rfc732a9  
    11/* emacs edit mode for this file is -*- C++ -*- */
    2 /* $Id: int_int.h,v 1.7 1998-01-22 10:54:22 schmidt Exp $ */
     2/* $Id: int_int.h,v 1.8 1998-03-17 15:56:18 schmidt Exp $ */
    33
    44#ifndef INCL_INT_INT_H
     
    77#include <config.h>
    88
    9 #include "cf_gmp.h"
    109#ifndef NOSTREAMIO
    1110#include <iostream.h>
     
    1514
    1615#include "int_cf.h"
     16#include "cf_gmp.h"
     17#include "gmpext.h"
    1718
    1819class InternalInteger : public InternalCF
     
    2021private:
    2122    MP_INT thempi;
    22     static int initialized;
    23     static MP_INT & MPI( const InternalCF * const c );
     23
     24    // auxilliary methods
     25    inline InternalCF * normalizeMyself ();
     26    inline InternalCF * uiNormalizeMyself ();
     27
     28    static inline InternalCF * normalizeMPI ( MP_INT & );
     29    static inline InternalCF * uiNormalizeMPI ( MP_INT & );
     30
     31    static inline MP_INT & MPI ( const InternalCF * const c );
     32
    2433public:
    2534    InternalInteger();
     
    95104};
    96105
    97 inline MP_INT & InternalInteger::MPI( const InternalCF * const c )
     106//{{{ inline InternalCF * InternalInteger::normalizeMyself, uiNormalizeMyself ()
     107//{{{ docu
     108//
     109// normalizeMyself(), uiNormalizeMyself() - normalize CO.
     110//
     111// If CO fits into an immediate integer, delete CO and return the
     112// immediate.  Otherwise, return a pointer to CO.
     113//
     114// `uiNormalizeMyself()' is the same as `normalizeMyself()'
     115// except that CO is expected to be non-begative.  In this case,
     116// we may use `mpz_get_ui()' to convert the underlying mpi into
     117// an immediate which is slightly faster than the signed variant.
     118//
     119// Note: We do not mind reference counting at this point!  CO is
     120// deleted unconditionally!
     121//
     122//}}}
     123inline InternalCF *
     124InternalInteger::normalizeMyself ()
     125{
     126    ASSERT( getRefCount() == 1, "internal error: must not delete CO" );
     127
     128    if ( mpz_is_imm( &thempi ) ) {
     129        InternalCF * result = int2imm( mpz_get_si( &thempi ) );
     130        delete this;
     131        return result;
     132    } else
     133        return this;
     134}
     135
     136inline InternalCF *
     137InternalInteger::uiNormalizeMyself ()
     138{
     139    ASSERT( getRefCount() == 1, "internal error: must not delete CO" );
     140
     141    if ( mpz_is_imm( &thempi ) ) {
     142        InternalCF * result = int2imm( mpz_get_ui( &thempi ) );
     143        delete this;
     144        return result;
     145    } else
     146        return this;
     147}
     148//}}}
     149
     150//{{{ static inline InternalCF * InternalInteger::normalizeMPI, uiNormalizeMPI ( MP_INT & aMpi )
     151//{{{ docu
     152//
     153// normalizeMPI(), uiNormalizeMPI() - normalize a mpi.
     154//
     155// If `aMpi' fits into an immediate integer, clear `aMpi' and
     156// return the immediate.  Otherwise, return a new
     157// `InternalInteger' with `aMpi' as underlying mpi.
     158//
     159// `uiNormalizeMPI()' is the same as `normalizeMPI()' except that
     160// `aMpi' is expected to be non-begative.  In this case, we may
     161// use `mpz_get_ui()' to convert `aMpi' into an immediate which
     162// is slightly faster than the signed variant.
     163//
     164//}}}
     165inline InternalCF *
     166InternalInteger::normalizeMPI ( MP_INT & aMpi )
     167{
     168    if ( mpz_is_imm( &aMpi ) ) {
     169        InternalCF * result = int2imm( mpz_get_si( &aMpi ) );
     170        mpz_clear( &aMpi );
     171        return result;
     172    } else
     173        return new InternalInteger( aMpi );
     174}
     175
     176inline InternalCF *
     177InternalInteger::uiNormalizeMPI ( MP_INT & aMpi )
     178{
     179    if ( mpz_is_imm( &aMpi ) ) {
     180        InternalCF * result = int2imm( mpz_get_ui( &aMpi ) );
     181        mpz_clear( &aMpi );
     182        return result;
     183    } else
     184        return new InternalInteger( aMpi );
     185}
     186//}}}
     187
     188//{{{ inline MP_INT & InternalInteger::MPI ( const InternalCF * const c )
     189//{{{ docu
     190//
     191// MPI() - return underlying mpi of `c'.
     192//
     193// `c' is expected to be an `InternalInteger *'.  `c's underlying
     194// mpi is returned.
     195//
     196//}}}
     197inline MP_INT &
     198InternalInteger::MPI ( const InternalCF * const c )
    98199{
    99200    return (((InternalInteger*)c)->thempi);
    100201}
     202//}}}
    101203
    102204#endif /* ! INCL_INT_INT_H */
Note: See TracChangeset for help on using the changeset viewer.