1 2 3 package com.ibm.icu.math; 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 79 80 public final class MathContext implements java.io.Serializable { 81 private static final java.lang.String $0="MathContext.nrx"; 82 83 84 85 96 public static final int PLAIN=0; 98 110 public static final int SCIENTIFIC=1; 112 124 public static final int ENGINEERING=2; 126 136 public static final int ROUND_CEILING=2; 137 138 147 public static final int ROUND_DOWN=1; 148 149 158 public static final int ROUND_FLOOR=3; 159 160 172 public static final int ROUND_HALF_DOWN=5; 173 174 190 public static final int ROUND_HALF_EVEN=6; 191 192 204 public static final int ROUND_HALF_UP=4; 205 206 216 public static final int ROUND_UNNECESSARY=7; 217 218 227 public static final int ROUND_UP=0; 228 229 230 231 245 int digits; 246 247 259 int form; 261 275 boolean lostDigits; 276 277 296 int roundingMode; 297 298 299 private static final int DEFAULT_FORM=SCIENTIFIC; 301 private static final int DEFAULT_DIGITS=9; 302 private static final boolean DEFAULT_LOSTDIGITS=false; 303 private static final int DEFAULT_ROUNDINGMODE=ROUND_HALF_UP; 304 305 306 307 private static final int MIN_DIGITS=0; private static final int MAX_DIGITS=999999999; private static final int ROUNDS[]=new int[]{ROUND_HALF_UP,ROUND_UNNECESSARY,ROUND_CEILING,ROUND_DOWN,ROUND_FLOOR,ROUND_HALF_DOWN,ROUND_HALF_EVEN,ROUND_UP}; 312 313 314 private static final java.lang.String ROUNDWORDS[]=new java.lang.String []{"ROUND_HALF_UP","ROUND_UNNECESSARY","ROUND_CEILING","ROUND_DOWN","ROUND_FLOOR","ROUND_HALF_DOWN","ROUND_HALF_EVEN","ROUND_UP"}; 316 317 318 319 320 321 private static final long serialVersionUID=7163376998892515376L; 323 324 325 335 public static final com.ibm.icu.math.MathContext DEFAULT=new com.ibm.icu.math.MathContext(DEFAULT_DIGITS,DEFAULT_FORM,DEFAULT_LOSTDIGITS,DEFAULT_ROUNDINGMODE); 336 337 338 339 340 341 342 357 358 public MathContext(int setdigits){ 359 this(setdigits,DEFAULT_FORM,DEFAULT_LOSTDIGITS,DEFAULT_ROUNDINGMODE); 360 return;} 361 362 363 382 383 public MathContext(int setdigits,int setform){ 384 this(setdigits,setform,DEFAULT_LOSTDIGITS,DEFAULT_ROUNDINGMODE); 385 return;} 386 387 408 409 public MathContext(int setdigits,int setform,boolean setlostdigits){ 410 this(setdigits,setform,setlostdigits,DEFAULT_ROUNDINGMODE); 411 return;} 412 413 434 435 public MathContext(int setdigits,int setform,boolean setlostdigits,int setroundingmode){super(); 436 437 438 if (setdigits!=DEFAULT_DIGITS) 440 { 441 if (setdigits<MIN_DIGITS) 442 throw new java.lang.IllegalArgumentException ("Digits too small:"+" "+setdigits); 443 if (setdigits>MAX_DIGITS) 444 throw new java.lang.IllegalArgumentException ("Digits too large:"+" "+setdigits); 445 } 446 { 447 if (setform==SCIENTIFIC){ 448 }else if (setform==ENGINEERING){ 450 }else if (setform==PLAIN){ 451 }else{ 452 throw new java.lang.IllegalArgumentException ("Bad form value:"+" "+setform); 453 } 454 } 455 if ((!(isValidRound(setroundingmode)))) 456 throw new java.lang.IllegalArgumentException ("Bad roundingMode value:"+" "+setroundingmode); 457 digits=setdigits; 458 form=setform; 459 lostDigits=setlostdigits; roundingMode=setroundingmode; 461 return;} 462 463 471 472 public int getDigits(){ 473 return digits; 474 } 475 476 486 487 public int getForm(){ 488 return form; 489 } 490 491 500 501 public boolean getLostDigits(){ 502 return lostDigits; 503 } 504 505 521 522 public int getRoundingMode(){ 523 return roundingMode; 524 } 525 526 563 564 public java.lang.String toString(){ 565 java.lang.String formstr=null; 566 int r=0; 567 java.lang.String roundword=null; 568 { 569 if (form==SCIENTIFIC) 570 formstr="SCIENTIFIC"; 571 else if (form==ENGINEERING) 572 formstr="ENGINEERING"; 573 else{ 574 formstr="PLAIN"; 575 } 576 } 577 {int $1=ROUNDS.length;r=0;r:for(;$1>0;$1--,r++){ 578 if (roundingMode==ROUNDS[r]) 579 { 580 roundword=ROUNDWORDS[r]; 581 break r; 582 } 583 } 584 } 585 return "digits="+digits+" "+"form="+formstr+" "+"lostDigits="+(lostDigits?"1":"0")+" "+"roundingMode="+roundword; 586 } 587 588 589 590 592 private static boolean isValidRound(int testround){ 593 int r=0; 594 {int $2=ROUNDS.length;r=0;r:for(;$2>0;$2--,r++){ 595 if (testround==ROUNDS[r]) 596 return true; 597 } 598 } 599 return false; 600 } 601 } 602 | Popular Tags |