Question: I've got an 8-byte fixed-point number using longs, with a constant denominator of (1 << 24). How do I do division of two Fixed8 values? Since I'm using C#, I can't simply cast to a larger integer. Or am I thinking too much in the language?

Thanks.

```
public struct Fixed8
{
    private long _numerator;
    public const long DENOMINATOR = 1 << 24;
}

```

Answer: 
You could use the [BigInteger Structure](http://msdn.microsoft.com/en-us/library/system.numerics.biginteger.aspx) to perform the calculations:

```
public static Fixed8 operator /(Fixed8 a, Fixed8 b)
{
    Fixed8 result;
    result._numerator = (long)( new BigInteger(a._numerator) *
                                new BigInteger(DENOMINATOR)  /
                                new BigInteger(b._numerator) );
    return result;
}

```

*Full code:*

```
public const long DENOMINATOR = 1 << 24;

private long _numerator;

public Fixed8(double value)
{
    _numerator = (long)(value * DENOMINATOR);
}

public static Fixed8 operator /(Fixed8 a, Fixed8 b)
{
    Fixed8 result;
    result._numerator = (long)( new BigInteger(a._numerator) * 
                                new BigInteger(DENOMINATOR)  / 
                                new BigInteger(b._numerator) );
    return result;
}

public static explicit operator double(Fixed8 a)
{
    return (double)a._numerator / (double)DENOMINATOR;
}

public override string ToString()
{
    return ((double)this).ToString();
}

```

*Example:*

```
var a = new Fixed8(7);
var b = new Fixed8(1.7);

Console.WriteLine(a);
Console.WriteLine(b);
Console.WriteLine(a / b);

```

*Output:*

```

7
1.69999998807907
4.11764705181122

```
Using a `System.Numerics.BigInteger` is fine. But in this specific case, a `System.Decimal` actually has enough precision. So here's my suggestion:

```
 public static Fixed8 operator /(Fixed8 a, Fixed8 b)
 {
   decimal resultNumerator = (decimal)a._numerator * DENOMINATOR / b._numerator;
   return new Fixed8 { _numerator = Convert.ToInt64(resultNumerator) };
 }

```