Пример #1
0
 public static double atan2(double v0, double v1)
 {
     if (double.IsNaN(v0) || double.IsNaN(v1))
     {
         return(double.NaN);
     }
     else if (double.IsInfinity(v0))
     {
         if (double.IsPositiveInfinity(v1))
         {
             return(pi * 0.25 * Math.Sign(v0));
         }
         else if (double.IsNegativeInfinity(v1))
         {
             return(pi * 0.75 * Math.Sign(v0));
         }
         else
         {
             return(pi * 0.5 * Math.Sign(v0));
         }
     }
     else if (double.IsInfinity(v1))
     {
         return(v1 > 0.0 ? 0.0 : pi *DoubleOps.Sign(v0));
     }
     return(Math.Atan2(v0, v1));
 }
Пример #2
0
        public static double copysign(object x, object y)
        {
            double val, sign;

            if (!Converter.TryConvertToDouble(x, out val) ||
                !Converter.TryConvertToDouble(y, out sign))
            {
                throw PythonOps.TypeError("TypeError: a float is required");
            }
            return(DoubleOps.Sign(sign) * Math.Abs(val));
        }
Пример #3
0
        private static double GetAngle(Complex num)
        {
            if (IsNaN(num))
            {
                return(double.NaN);
            }

            if (double.IsPositiveInfinity(num.Real))
            {
                if (double.IsPositiveInfinity(num.Imaginary()))
                {
                    return(Math.PI * 0.25);
                }
                else if (double.IsNegativeInfinity(num.Imaginary()))
                {
                    return(Math.PI * -0.25);
                }
                else
                {
                    return(0.0);
                }
            }

            if (double.IsNegativeInfinity(num.Real))
            {
                if (double.IsPositiveInfinity(num.Imaginary()))
                {
                    return(Math.PI * 0.75);
                }
                else if (double.IsNegativeInfinity(num.Imaginary()))
                {
                    return(Math.PI * -0.75);
                }
                else
                {
                    return(DoubleOps.Sign(num.Imaginary()) * Math.PI);
                }
            }

            if (num.Real == 0.0)
            {
                if (num.Imaginary() != 0.0)
                {
                    return(Math.PI * 0.5 * Math.Sign(num.Imaginary()));
                }
                else
                {
                    return((DoubleOps.IsPositiveZero(num.Real) ? 0.0 : Math.PI) * DoubleOps.Sign(num.Imaginary()));
                }
            }

            return(Math.Atan2(num.Imaginary(), num.Real));
        }
        private void AppendFloat(char type)
        {
            double v;

            if (!Converter.TryConvertToDouble(_opts.Value, out v))
            {
                throw PythonOps.TypeError("float argument required");
            }

            // scientific exponential format
            Debug.Assert(type == 'E' || type == 'e' ||
                         // floating point decimal
                         type == 'F' || type == 'f' ||
                         // Same as "e" if exponent is less than -4 or more than precision, "f" otherwise.
                         type == 'G' || type == 'g');

            bool forceDot = false;

            // update our precision first...
            if (_opts.Precision != UnspecifiedPrecision)
            {
                if (_opts.Precision == 0 && _opts.AltForm)
                {
                    forceDot = true;
                }
                if (_opts.Precision > 50)
                {
                    _opts.Precision = 50;
                }
            }
            else
            {
                // alternate form (#) specified, set precision to zero...
                if (_opts.AltForm)
                {
                    _opts.Precision = 0;
                    forceDot        = true;
                }
                else
                {
                    _opts.Precision = 6;
                }
            }

            type = AdjustForG(type, v);
            _nfi.NumberDecimalDigits = _opts.Precision;

            // then append
            if (_opts.LeftAdj)
            {
                AppendLeftAdj(v, DoubleOps.Sign(v) >= 0, type);
            }
            else if (_opts.ZeroPad)
            {
                AppendZeroPadFloat(v, type);
            }
            else
            {
                AppendNumeric(v, DoubleOps.Sign(v) >= 0, type);
            }
            if (DoubleOps.Sign(v) < 0 && v > -1 && _buf[0] != '-')
            {
                FixupFloatMinus();
            }

            if (forceDot)
            {
                FixupAltFormDot(v);
            }
        }
Пример #5
0
 public static double copysign(double x, double y)
 {
     return(DoubleOps.Sign(y) * Math.Abs(x));
 }