Contains parameters for controlling the precision, rounding, and exponent range of arbitrary-precision numbers.
Beispiel #1
0
        /// <include file='../docs.xml'
        /// path='docs/doc[@name="M:PeterO.TrapException.#ctor(System.Int32,PeterO.PrecisionContext,System.Object)"]/*'/>
        public TrapException(int flag, PrecisionContext ctx, Object result) :
            base(String.Empty)
        {
            Object wrappedResult = result;
            var    ed            = result as EDecimal;
            var    er            = result as ERational;
            var    ef            = result as EFloat;

            if (ed != null)
            {
                wrappedResult = new ExtendedDecimal(ed);
            }
            if (er != null)
            {
                wrappedResult = new ExtendedRational(er);
            }
            if (ef != null)
            {
                wrappedResult = new ExtendedFloat(ef);
            }
            this.ete = new ETrapException(
                flag,
                ctx == null ? null : ctx.Ec,
                wrappedResult);
        }
Beispiel #2
0
 public static ExtendedFloat FromString(
     string str,
     int offset,
     int length,
     PrecisionContext ctx)
 {
     try {
         return(new ExtendedFloat(
                    EFloat.FromString(
                        str,
                        offset,
                        length,
                        ctx == null ? null : ctx.Ec)));
     } catch (ETrapException ex) {
         throw TrapException.Create(ex);
     }
 }
Beispiel #3
0
 /// <include file='../docs.xml'
 /// path='docs/doc[@name="M:PeterO.TrapException.#ctor(System.Int32,PeterO.PrecisionContext,System.Object)"]/*'/>
 public TrapException(int flag, PrecisionContext ctx, Object result)
     : base(String.Empty)
 {
     Object wrappedResult = result;
       var ed = result as EDecimal;
       var er = result as ERational;
       var ef = result as EFloat;
       if (ed != null) {
      wrappedResult = new ExtendedDecimal(ed);
     }
       if (er != null) {
      wrappedResult = new ExtendedRational(er);
     }
       if (ef != null) {
      wrappedResult = new ExtendedFloat(ef);
     }
       this.ete = new ETrapException(
       flag,
       ctx == null ? null : ctx.Ec,
       wrappedResult);
 }
Beispiel #4
0
 /// <summary> Initializes a new PrecisionContext that is a copy of another
 /// PrecisionContext. </summary>
 /// <returns>A PrecisionContext object.</returns>
 public PrecisionContext Copy() {
   PrecisionContext pcnew=new PrecisionContext(0,this.rounding,
                                               0,0,this.clampNormalExponents);
   pcnew.hasFlags = this.hasFlags;
   pcnew.flags = this.flags;
   pcnew.exponentMax = this.exponentMax;
   pcnew.exponentMin = this.exponentMin;
   pcnew.hasExponentRange = this.hasExponentRange;
   pcnew.bigintPrecision = this.bigintPrecision;
   pcnew.rounding = this.rounding;
   pcnew.clampNormalExponents = this.clampNormalExponents;
   return pcnew;
 }
Beispiel #5
0
 private PrecisionContext SetRounding(PrecisionContext ctx, string round)
 {
     if(round.Equals(">"))ctx=ctx.WithRounding(Rounding.Ceiling);
       if(round.Equals("<"))ctx=ctx.WithRounding(Rounding.Floor);
       if(round.Equals("0"))ctx=ctx.WithRounding(Rounding.Down);
       if(round.Equals("=0"))ctx=ctx.WithRounding(Rounding.HalfEven);
       if(round.Equals("h>"))ctx=ctx.WithRounding(Rounding.HalfUp);
       if(round.Equals("h<"))ctx=ctx.WithRounding(Rounding.HalfDown);
       return ctx;
 }
Beispiel #6
0
 private string RoundingString(PrecisionContext ctx, string round)
 {
     if(round.Equals(">"))return ".WithRounding(Rounding.Ceiling)";
       if(round.Equals("<"))return ".WithRounding(Rounding.Floor)";
       if(round.Equals("0"))return ".WithRounding(Rounding.Down)";
       if(round.Equals("=0"))return ".WithRounding(Rounding.HalfEven)";
       if(round.Equals("h>"))return ".WithRounding(Rounding.HalfUp)";
       if(round.Equals("h<"))return ".WithRounding(Rounding.HalfDown)";
       if(round.Equals("+"))return ".WithRounding(Rounding.Up)";
       if(round.Equals("u"))return ".WithRounding(Rounding.Unnecessary)";
       return "";
 }