Exemplo n.º 1
0
Arquivo: Real.cs Projeto: suzuke/forge
        public static Real Atan2(Real F1, Real F2)
        {
            if (F2.RawValue == 0 && F1.RawValue == 0)
            {
                return((Real)0);
            }

            Real result = (Real)0;

            if (F2 > 0)
            {
                result = Atan(F1 / F2);
            }
            else if (F2 < 0)
            {
                if (F1 >= 0)
                {
                    result = (PI - Atan(Abs(F1 / F2)));
                }
                else
                {
                    result = (PI - Atan(Abs(F1 / F2))).Inverse;
                }
            }
            else
            {
                result = (F1 >= 0 ? PI : PI.Inverse) / Real.Create(2, true);
            }

            return(result);
        }
Exemplo n.º 2
0
Arquivo: Real.cs Projeto: suzuke/forge
            public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
            {
                if (reader.TokenType != JsonToken.Float)
                {
                    throw new InvalidOperationException("Expected float when deserializing Real");
                }

                return(Real.Create((double)reader.Value));
            }
Exemplo n.º 3
0
Arquivo: Real.cs Projeto: suzuke/forge
        /// <summary>
        /// Create a fixed-int number from parts. For example, to create 1.5 pass in 1 and 500.
        /// </summary>
        /// <param name="PreDecimal">The number above the decimal. For 1.5, this would be 1.</param>
        /// <param name="PostDecimal">The number below the decimal, to three digits. For 1.5, this
        /// would be 500. For 1.005, this would be 5.</param>
        /// <returns>A fixed-int representation of the number parts</returns>
        public static Real FromParts(int PreDecimal, int PostDecimal)
        {
            Real f = Real.Create(PreDecimal, true);

            if (PostDecimal != 0)
            {
                f.RawValue += (Real.Create(PostDecimal) / 1000).RawValue;
            }

            return(f);
        }
Exemplo n.º 4
0
Arquivo: Real.cs Projeto: suzuke/forge
 private static Real sin_lookup(Real i, Real j)
 {
     if (j > 0 && j < Real.Create(10, false) && i < Real.Create(90, false))
     {
         return(Real.Create(SIN_TABLE[i.RawValue], false) +
                ((Real.Create(SIN_TABLE[i.RawValue + 1], false) - Real.Create(SIN_TABLE[i.RawValue], false)) /
                 Real.Create(10, false)) * j);
     }
     else
     {
         return(Real.Create(SIN_TABLE[i.RawValue], false));
     }
 }
Exemplo n.º 5
0
Arquivo: Real.cs Projeto: suzuke/forge
        public static Real Asin(Real F)
        {
            bool isNegative = F < 0;

            F = Abs(F);

            if (F > Real.OneF)
            {
                throw new ArithmeticException("Bad Asin Input:" + F.AsFloat);
            }

            Real f1 = mul(mul(mul(mul(Real.Create(145103 >> Real.SHIFT_AMOUNT, false), F) -
                                  Real.Create(599880 >> Real.SHIFT_AMOUNT, false), F) +
                              Real.Create(1420468 >> Real.SHIFT_AMOUNT, false), F) -
                          Real.Create(3592413 >> Real.SHIFT_AMOUNT, false), F) +
                      Real.Create(26353447 >> Real.SHIFT_AMOUNT, false);
            Real f2 = PI / Real.Create(2, true) - (Sqrt(Real.OneF - F) * f1);

            return(isNegative ? f2.Inverse : f2);
        }
Exemplo n.º 6
0
Arquivo: Real.cs Projeto: suzuke/forge
        public static Real Sin(Real i)
        {
            Real j = (Real)0;

            for (; i < 0; i += Real.Create(25736, false))
            {
                ;
            }
            if (i > Real.Create(25736, false))
            {
                i %= Real.Create(25736, false);
            }
            Real k = (i * Real.Create(10, false)) / Real.Create(714, false);

            if (i != 0 && i != Real.Create(6434, false) && i != Real.Create(12868, false) &&
                i != Real.Create(19302, false) && i != Real.Create(25736, false))
            {
                j = (i * Real.Create(100, false)) / Real.Create(714, false) - k * Real.Create(10, false);
            }
            if (k <= Real.Create(90, false))
            {
                return(sin_lookup(k, j));
            }
            if (k <= Real.Create(180, false))
            {
                return(sin_lookup(Real.Create(180, false) - k, j));
            }
            if (k <= Real.Create(270, false))
            {
                return(sin_lookup(k - Real.Create(180, false), j).Inverse);
            }
            else
            {
                return(sin_lookup(Real.Create(360, false) - k, j).Inverse);
            }
        }
Exemplo n.º 7
0
Arquivo: Real.cs Projeto: suzuke/forge
 public static Real Cos(Real i)
 {
     return(Sin(i + Real.Create(6435, false)));
 }
Exemplo n.º 8
0
Arquivo: Real.cs Projeto: suzuke/forge
 public static Real operator >>(Real one, int Amount)
 {
     return(Real.Create(one.RawValue >> Amount, false));
 }