Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiply instead of divide #9

Open
jonassix opened this issue Jun 26, 2019 · 0 comments
Open

Multiply instead of divide #9

jonassix opened this issue Jun 26, 2019 · 0 comments

Comments

@jonassix
Copy link

jonassix commented Jun 26, 2019

    public static void Divide(out Int128 c, ref Int128 a, int b)
        {
            if (a.IsNegative)
            {
                UInt128 aneg;
                UInt128.Negate(out aneg, ref a.v);
                if (b < 0)
                    UInt128.Multiply(out c.v, ref aneg, (uint)(-b));
                else
                {
                    UInt128.Multiply(out c.v, ref aneg, (uint)b);
                    UInt128.Negate(ref c.v);
                }
            }
            else
            {
                if (b < 0)
                {
                    UInt128.Multiply(out c.v, ref a.v, (uint)(-b));
                    UInt128.Negate(ref c.v);
                }
                else
                    UInt128.Multiply(out c.v, ref a.v, (uint)b);
            }
            Debug.Assert((BigInteger)c == (BigInteger)a / (BigInteger)b);
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant