Exemplo n.º 1
0
        public static Real Get(string value, int @base = 10)
        {
            if (value.Contains("#"))
            {
                double lowerBound = double.Parse(value.Replace('#', '0'));

                char   replace    = @base > 16 ? (char)('a' + (@base - 11)) : (char)('0' + @base - 1);
                double upperBound = double.Parse(value.Replace('#', replace));

                double primaryValue = (lowerBound + upperBound) / 2;

                InexactReal key = InexactReal.Get(lowerBound, upperBound, primaryValue, false);
                if (cache.ContainsKey(key))
                {
                    return(cache[key]);
                }
                Real result = new Real(key);
                cache.Add(key, result);
                return(result);
            }
            else
            {
                ExactReal key = ExactReal.Get(decimal.Parse(Integer.Get(value, @base).ToString()));
                if (cache.ContainsKey(key))
                {
                    return(cache[key]);
                }
                Real result = new Real(key);
                cache.Add(key, result);
                return(result);
            }
        }
Exemplo n.º 2
0
        public static Real Get(double value)
        {
            InexactReal container = InexactReal.Get(value);

            if (cache.ContainsKey(container))
            {
                return(cache[container]);
            }
            cache.Add(container, new Real(value));
            return(cache[container]);
        }
Exemplo n.º 3
0
#pragma warning disable RECS0146 // Member hides static member from outer class
            public static InexactReal Get(double lowerBound, double upperBound, double primaryValue, bool robust)
#pragma warning restore RECS0146 // Member hides static member from outer class
            {
                if (upperBound < lowerBound)
                {
                    return(Undefined);
                }
                var key = (lowerBound, upperBound, primaryValue, robust);

                if (cache.ContainsKey(key))
                {
                    return(cache[key]);
                }
                InexactReal result = new InexactReal(lowerBound, upperBound, primaryValue, robust);

                cache.Add(key, result);
                return(result);
            }
Exemplo n.º 4
0
 Real(double value)
 {
     Data = InexactReal.Get(value);
 }