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(decimal value)
        {
            Number cachedKey = ExactReal.Get(value);

            if (cache.ContainsKey(cachedKey))
            {
                return(cache[cachedKey]);
            }
            Real result = new Real(cachedKey);

            cache.Add(cachedKey, result);
            return(result);
        }