[BACK]Return to CMO_ZZ.java CVS log [TXT][DIR] Up to [local] / OpenXM / src / OpenMath / ORG / openxm / tam

File: [local] / OpenXM / src / OpenMath / ORG / openxm / tam / CMO_ZZ.java (download)

Revision 1.3, Wed Oct 11 08:32:15 2000 UTC (23 years, 8 months ago) by ohara
Branch: MAIN
CVS Tags: maekawa-ipv6, R_1_3_1-2, RELEASE_1_3_1_13b, RELEASE_1_2_3_12, RELEASE_1_2_3, RELEASE_1_2_2_KNOPPIX_b, RELEASE_1_2_2_KNOPPIX, RELEASE_1_2_2, RELEASE_1_2_1, KNOPPIX_2006, HEAD, DEB_REL_1_2_3-9
Changes since 1.2: +5 -5 lines

I have replaced all stdout by stderr, that is,
System.out.println ==> System.err.println

/**
 * $OpenXM: OpenXM/src/OpenMath/ORG/openxm/tam/CMO_ZZ.java,v 1.3 2000/10/11 08:32:15 ohara Exp $
 */
package ORG.openxm.tam;

import java.io.*;
import java.math.BigInteger;

/**
 * CMO $B7A<0$N(B ZZ $B7?$rI=$7$^$9(B.
 */
final public class CMO_ZZ extends CMO{
  private BigInteger num;

  /**
   * num $B$rCM$H$9$k(B ZZ $B$r:n@.$7$^$9(B.
   */
  public CMO_ZZ(BigInteger num){
    this.num = num;
  }

  public CMO_ZZ(String str) throws NumberFormatException{
    if(str.startsWith("+")){
      this.num = new BigInteger(str.substring(1));
    }else{
      this.num = new BigInteger(str);
    }
  }

  /**
   * $BCM$r(B int $B7?$GF@$^$9(B.
   */
  public int intValue(){
    return num.intValue();
  }

  /**
   * $BCM$r(B BigInteger $B7?$GF@$^$9(B.
   */
  public BigInteger BigIntValue(){
    return num;
  }

  public int DISCRIMINATOR(){
    return CMO.ZZ;
  }

  static private int sign(int a){
    if(a>0){
      return 1;
    }else if(a<0){
      return -1;
    }
    return 0;
  }

  public void sendByObject(OpenXMstream os) throws IOException{
    if(this.num.signum()==0){
      os.writeInt(0);
    }else{
      int len = (this.num.abs().bitLength()+31)/32;
      //System.err.println("sing0: "+this.num.bitLength());
      //System.err.println("sing1: "+this.num.abs().bitLength());

      os.writeInt(this.num.signum()*len);
      //System.err.println("sing: "+this.num.signum()*len);

      for(BigInteger a = this.num.abs();a.compareTo(new BigInteger("0"))>0;
	  a = a.divide(new BigInteger("4294967296"))){
	os.writeInt(a.remainder(new BigInteger("4294967296")).intValue());
	//System.err.println("remaind: "+a.remainder(new BigInteger("4294967296")).intValue());
      }
    }
  }

  static protected CMO receive(OpenXMstream is) throws IOException{
    int len;
    BigInteger a = new BigInteger("0");

    len = is.readInt();
    for(int i=0;i<Math.abs(len);i++){
      BigInteger b = new BigInteger(""+is.readInt());

      b = b.add(new BigInteger("4294967296")).remainder(new BigInteger("4294967296"));
      b = new BigInteger("4294967296").pow(i).multiply(b);
      a = a.add(b);
    }

    if(len<0){
      a = a.negate();
    }

    return new CMO_ZZ(a);
  }

  public String toCMOexpressionByObject() throws NumberFormatException{
    return "CMO_ZZ,"+ this.num;
  }
}