Esempio n. 1
0
File: EFloat.cs Progetto: basp/linie
        public static EFloat operator *(EFloat a, EFloat b)
        {
            var v    = a.v * b.v;
            var prod = new[]
            {
                a.LowerBound *b.LowerBound,
                a.UpperBound *b.LowerBound,
                a.LowerBound *b.UpperBound,
                a.UpperBound *b.UpperBound,
            };

            var low = Utils.NextFloatDown(
                Math.Min(
                    Math.Min(prod[0], prod[1]),
                    Math.Min(prod[2], prod[3])));

            var high = Utils.NextFloatUp(
                Math.Max(
                    Math.Max(prod[0], prod[1]),
                    Math.Max(prod[2], prod[3])));

#if DEBUG
            var vp = a.vp * b.vp;
            EFloat.Validate(v, vp, low, high);
            return(new EFloat(v, vp, low, high));
#else
            return(new EFloat(v, low, high));
#endif
        }
Esempio n. 2
0
File: EFloat.cs Progetto: basp/linie
        public static EFloat operator -(EFloat a, EFloat b)
        {
            var v    = a.v - b.v;
            var low  = Utils.NextFloatDown(a.LowerBound - b.UpperBound);
            var high = Utils.NextFloatUp(a.UpperBound - b.LowerBound);

#if DEBUG
            var vp = a.vp - b.vp;
            EFloat.Validate(v, vp, low, high);
            return(new EFloat(v, vp, low, high));
#else
            return(new EFloat(v, low, high));
#endif
        }
Esempio n. 3
0
File: EFloat.cs Progetto: basp/linie
        // Negative values of `f` are not supported
        public static EFloat Sqrt(EFloat f)
        {
            var v    = (float)Math.Sqrt(f.v);
            var low  = Utils.NextFloatDown((float)Math.Sqrt(f.low));
            var high = Utils.NextFloatUp((float)Math.Sqrt(f.high));

#if DEBUG
            var vp = Math.Sqrt(f.vp);
            EFloat.Validate(v, vp, low, high);
            return(new EFloat(v, vp, low, high));
#else
            return(new EFloat(v, low, high));
#endif
        }
Esempio n. 4
0
File: EFloat.cs Progetto: basp/linie
        public static EFloat operator -(EFloat a)
        {
            var v    = -a.v;
            var low  = -a.high;
            var high = -a.low;

#if DEBUG
            var vp = -a.vp;
            EFloat.Validate(v, vp, low, high);
            return(new EFloat(v, vp, low, high));
#else
            return(new EFloat(v, low, high));
#endif
        }
Esempio n. 5
0
File: EFloat.cs Progetto: basp/linie
        public static EFloat operator /(EFloat a, EFloat b)
        {
            var v = a.v / b.v;

            float low, high;

            if (b.low < 0 && b.high > 0)
            {
                // Guard against divide by zero;
                // return interval of everything
                low  = float.NegativeInfinity;
                high = float.PositiveInfinity;
            }
            else
            {
                var div = new[]
                {
                    a.LowerBound / b.LowerBound,
                    a.UpperBound / b.LowerBound,
                    a.LowerBound / b.UpperBound,
                    a.UpperBound / b.UpperBound,
                };

                low = Utils.NextFloatDown(
                    Math.Min(
                        Math.Min(div[0], div[1]),
                        Math.Min(div[2], div[3])));

                high = Utils.NextFloatUp(
                    Math.Max(
                        Math.Max(div[0], div[1]),
                        Math.Max(div[2], div[3])));
            }

#if DEBUG
            var vp = a.vp / b.vp;
            EFloat.Validate(v, vp, low, high);
            return(new EFloat(v, vp, low, high));
#else
            return(new EFloat(v, low, high));
#endif
        }