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

Annotation of OpenXM/src/OpenMath/ORG/openxm/tam/CMO_ZZ.java, Revision 1.1

1.1     ! tam         1: /**
        !             2:  * $OpenXM$
        !             3:  */
        !             4: package ORG.openxm.tam;
        !             5:
        !             6: import java.io.*;
        !             7: import java.math.BigInteger;
        !             8:
        !             9: /**
        !            10:  * CMO $B7A<0$N(B ZZ $B7?$rI=$7$^$9(B.
        !            11:  */
        !            12: final public class CMO_ZZ extends CMO{
        !            13:   private BigInteger num;
        !            14:
        !            15:   /**
        !            16:    * num $B$rCM$H$9$k(B ZZ $B$r:n@.$7$^$9(B.
        !            17:    */
        !            18:   public CMO_ZZ(BigInteger num){
        !            19:     this.num = num;
        !            20:   }
        !            21:
        !            22:   public CMO_ZZ(String str) throws NumberFormatException{
        !            23:     if(str.startsWith("+")){
        !            24:       this.num = new BigInteger(str.substring(1));
        !            25:     }else{
        !            26:       this.num = new BigInteger(str);
        !            27:     }
        !            28:   }
        !            29:
        !            30:   /**
        !            31:    * $BCM$r(B int $B7?$GF@$^$9(B.
        !            32:    */
        !            33:   public int intValue(){
        !            34:     return num.intValue();
        !            35:   }
        !            36:
        !            37:   /**
        !            38:    * $BCM$r(B BigInteger $B7?$GF@$^$9(B.
        !            39:    */
        !            40:   public BigInteger BigIntValue(){
        !            41:     return num;
        !            42:   }
        !            43:
        !            44:   public int DISCRIMINATOR(){
        !            45:     return CMO.ZZ;
        !            46:   }
        !            47:
        !            48:   static private int sign(int a){
        !            49:     if(a>0){
        !            50:       return 1;
        !            51:     }else if(a<0){
        !            52:       return -1;
        !            53:     }
        !            54:     return 0;
        !            55:   }
        !            56:
        !            57:   public void sendByObject(OpenXMconnection os) throws IOException{
        !            58:     if(this.num.signum()==0){
        !            59:       os.writeInt(0);
        !            60:     }else{
        !            61:       int len = (this.num.abs().bitLength()+31)/32;
        !            62:       //System.out.println("sing0: "+this.num.bitLength());
        !            63:       //System.out.println("sing1: "+this.num.abs().bitLength());
        !            64:
        !            65:       os.writeInt(this.num.signum()*len);
        !            66:       //System.out.println("sing: "+this.num.signum()*len);
        !            67:
        !            68:       for(BigInteger a = this.num.abs();a.compareTo(new BigInteger("0"))>0;
        !            69:          a = a.divide(new BigInteger("4294967296"))){
        !            70:        os.writeInt(a.remainder(new BigInteger("4294967296")).intValue());
        !            71:        //System.out.println("remaind: "+a.remainder(new BigInteger("4294967296")).intValue());
        !            72:       }
        !            73:     }
        !            74:   }
        !            75:
        !            76:   static protected CMO receive(OpenXMconnection is) throws IOException{
        !            77:     int len;
        !            78:     BigInteger a = new BigInteger("0");
        !            79:
        !            80:     len = is.readInt();
        !            81:     for(int i=0;i<Math.abs(len);i++){
        !            82:       BigInteger b = new BigInteger(""+is.readInt());
        !            83:
        !            84:       b = b.add(new BigInteger("4294967296")).remainder(new BigInteger("4294967296"));
        !            85:       b = new BigInteger("4294967296").pow(i).multiply(b);
        !            86:       a = a.add(b);
        !            87:     }
        !            88:
        !            89:     if(len<0){
        !            90:       a = a.negate();
        !            91:     }
        !            92:
        !            93:     return new CMO_ZZ(a);
        !            94:   }
        !            95:
        !            96:   public String toCMOexpressionByObject() throws NumberFormatException{
        !            97:     return "CMO_ZZ,"+ this.num;
        !            98:   }
        !            99: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>