BigInteger.LongValue C# (CSharp) Method

LongValue() public method

public LongValue ( ) : long
return long
        public long LongValue()
        {
                long val = 0;

                val = (long)data[0];
                try
                {       // exception if maxLength = 1
                        val |= (long)data[1] << 32;
                }
                catch(Exception)
                {
                        if((data[0] & 0x80000000) != 0) // negative
                                val = (int)data[0];
                }

                return val;
        }

Usage Example

Ejemplo n.º 1
0
        private static BigInteger GetNearby(BigInteger significand, int binExp, int offset)
        {
            int        nExtraBits = 1;
            int        nDec       = (int)Math.Round(3.0 + (64 + nExtraBits) * Math.Log10(2.0));
            BigInteger newFrac    = (significand << nExtraBits).Add(new BigInteger(offset));

            int gg = 64 + nExtraBits - binExp - 1;

            decimal bd = new decimal(newFrac.LongValue());

            if (gg > 0)
            {
                bd = bd / (new decimal((BigInteger.ONE << gg).LongValue()));
            }
            else
            {
                BigInteger frac = newFrac;
                while (frac.BitLength() + binExp < 180)
                {
                    frac = frac * (BigInteger.TEN);
                }
                int binaryExp = binExp - newFrac.BitLength() + frac.BitLength();

                bd = new decimal((frac >> (frac.BitLength() - binaryExp - 1)).LongValue());
            }

            /*int excessPrecision = bd.Precision() - nDec;
             * if (excessPrecision > 0)
             * {
             *  bd = bd.SetScale(bd.Scale() - excessPrecision, BigDecimal.ROUND_HALF_UP);
             * }
             * return bd.unscaledValue();*/
            throw new NotImplementedException();
        }
All Usage Examples Of BigInteger::LongValue