示例#1
0
    public static InuFloat FromScaledValue(long _v)
    {
        InuFloat result = new InuFloat();

        result.ScaledSet(_v);
        return(result);
    }
示例#2
0
    public static InuFloat Float(InuFloat min, InuFloat max)
    {
        InuFloat result = new InuFloat();

        result.ScaledSet(Long(min.i, max.i));
        return(result);
    }
示例#3
0
    public static InuFloat Sqrt(InuFloat _sqr)
    {
        //Debug.LogError("111: " + _sqr);
        if (_sqr.i < 0)
        {
            return(InuFloat.ZERO);
        }
        if (_sqr.i == 0)
        {
            return(InuFloat.ZERO);
        }
        long b = _sqr.i; // big
        long s = 0;

        if (_sqr.i > INT_SCALE * INT_SCALE)
        {
            if (b > 100)
            {
                b = 10;
                while (b * (b / INT_SCALE) < _sqr.i)
                {
                    b *= 10;
                }
            }
            //int loop = 0;
            while (b - s > 1)
            {
                long m = (b + s) / 2;
                if (m * (m / INT_SCALE) > _sqr.i)
                {
                    b = m;
                }
                else
                {
                    s = m;
                }

                //loop++;
            }
        }
        else
        {
            b *= 10;
            //long new_scale = INT_SCALE;// *INT_SCALE;
            //long sqr_i = _sqr.i;// *INT_SCALE;
            //b *= INT_SCALE;
            //s *= INT_SCALE;
            while (b - s > 1)
            {
                long m = (b + s) / 2;
                if (m * m > _sqr.i * INT_SCALE)
                {
                    b = m;
                }
                else
                {
                    s = m;
                }

                //loop++;
            }
            //b /= INT_SCALE;
            //s /= INT_SCALE;
        }
        //Debug.LogError("loop: " + loop);
        InuFloat result = new InuFloat();

        if (s == 0)
        {
            result.ScaledSet(1);
        }
        else
        {
            result.ScaledSet(s);
        }
        //Debug.LogError("222: " + result);
        return(result);
    }