示例#1
0
 /** Calcaulte the simplest rational between two reals. */
 public static RealNum rationalize(RealNum x, RealNum y)
 {
     // This algorithm is by Alan Bawden.  It has been transcribed
     // with permission from C-Gambit, copyright Marc Feeley.
     if (x.grt (y))
         return simplest_rational2 (y, x);
     else if (! (y.grt(x)))
         return x;
     else if (x.sign() > 0)
         return simplest_rational2 (x, y);
     else if (y.isNegative ())
         return (RealNum) (simplest_rational2 ((RealNum)y.neg(),
                                               (RealNum)x.neg())).neg();
     else
         return IntNum.zero ();
 }
示例#2
0
        public RealNum max(RealNum x)
        {
            RealNum result = grt(x) ? this : x;

            return(result);
        }
示例#3
0
 private static RealNum simplest_rational2(RealNum x, RealNum y)
 {
     RealNum fx = x.toInt (FLOOR);
     RealNum fy = y.toInt (FLOOR);
     if (! x.grt(fx))
         return fx;
     else if (fx.Equals(fy))
         {
             RealNum n = (RealNum) IntNum.one().div(y.sub(fy));
             RealNum d = (RealNum) IntNum.one().div(x.sub(fx));
             return (RealNum) fx.add(IntNum.one().div(simplest_rational2 (n, d)),
                                     1);
         }
     else
         return (RealNum) fx.add(IntNum.one(), 1);
 }
示例#4
0
文件: RealNum.cs 项目: vic/ioke
 public static RealNum add(RealNum x, RealNum y, int k)
 {
     return (RealNum)(x.add(y, k));
 }
示例#5
0
文件: RealNum.cs 项目: vic/ioke
 public RealNum min(RealNum x)
 {
     RealNum result = grt (x) ? x : this;
     return result;
 }
示例#6
0
文件: RealNum.cs 项目: vic/ioke
 public RealNum max(RealNum x)
 {
     RealNum result = grt (x) ? this : x;
     return result;
 }
示例#7
0
文件: RealNum.cs 项目: vic/ioke
 public static RealNum times(RealNum x, RealNum y)
 {
     return (RealNum)(x.mul(y));
 }
示例#8
0
文件: RealNum.cs 项目: vic/ioke
 public static RealNum divide(RealNum x, RealNum y)
 {
     return (RealNum)(x.div(y));
 }