Ejemplo n.º 1
0
        private void FixupFloatMinus(double value)
        {
            // Ruby always appends a minus sign even if precision is 0 and the value would appear to be zero.
            //   sprintf("%.0f", -0.1) => "-0"
            // Ruby also displays a "-0.0" for a negative zero whereas the CLR displays just "0.0"
            bool fNeedMinus;

            if (value == 0.0)
            {
                fNeedMinus = FloatOps.IsNegativeZero(value);
            }
            else
            {
                fNeedMinus = true;
                for (int i = 0; i < _buf.Length; i++)
                {
                    char c = _buf[i];
                    if (c != '.' && c != '0' && c != ' ')
                    {
                        fNeedMinus = false;
                        break;
                    }
                }
            }

            if (fNeedMinus)
            {
                if (_opts.FieldWidth != 0)
                {
                    // trim us back down to the correct field width...
                    if (_buf[_buf.Length - 1] == ' ')
                    {
                        _buf.Insert(0, "-");
                        _buf.Remove(_buf.Length - 1, 1);
                    }
                    else
                    {
                        int index = 0;
                        while (_buf[index] == ' ')
                        {
                            index++;
                        }
                        if (index > 0)
                        {
                            index--;
                        }
                        _buf[index] = '-';
                    }
                }
                else
                {
                    _buf.Insert(0, "-");
                }
            }
        }
Ejemplo n.º 2
0
        public static object Truncate(RubyContext /*!*/ context, object self)
        {
            double floatSelf = Protocols.ConvertToFloat(context, self);

            return(FloatOps.ToInt(floatSelf));
        }
Ejemplo n.º 3
0
 public static object Floor(RubyContext /*!*/ context, object self)
 {
     return(FloatOps.Floor(Protocols.ConvertToFloat(context, self)));
 }
Ejemplo n.º 4
0
        public static object Round(RubyContext /*!*/ context, object self)
        {
            double floatSelf = Protocols.ConvertToFloat(context, self);

            return(FloatOps.Round(floatSelf));
        }
Ejemplo n.º 5
0
 public static object Compare(RubyContext /*!*/ context, BigInteger /*!*/ self, double other)
 {
     return(FloatOps.Compare(ToFloat(context, self), other));
 }