| 1874 | */ |
| 1875 | |
| 1876 | void PositiveDivide(Integer &remainder, Integer "ient, |
| 1877 | const Integer &a, const Integer &b) |
| 1878 | { |
| 1879 | unsigned aSize = a.WordCount(); |
| 1880 | unsigned bSize = b.WordCount(); |
| 1881 | |
| 1882 | if (!bSize) |
| 1883 | { |
| 1884 | #ifdef THROW_EXCEPTIONS |
| 1885 | throw Integer::DivideByZero(); |
| 1886 | #else |
| 1887 | return; |
| 1888 | #endif |
| 1889 | } |
| 1890 | |
| 1891 | if (a.PositiveCompare(b) == -1) |
| 1892 | { |
| 1893 | remainder = a; |
| 1894 | remainder.sign = Integer::POSITIVE; |
| 1895 | quotient = Integer::Zero(); |
| 1896 | return; |
| 1897 | } |
| 1898 | |
| 1899 | aSize += aSize%2; // round up to next even number |
| 1900 | bSize += bSize%2; |
| 1901 | |
| 1902 | remainder.reg.CleanNew(RoundupSize(bSize)); |
| 1903 | remainder.sign = Integer::POSITIVE; |
| 1904 | quotient.reg.CleanNew(RoundupSize(aSize-bSize+2)); |
| 1905 | quotient.sign = Integer::POSITIVE; |
| 1906 | |
| 1907 | SecWordBlock T(aSize+2*bSize+4); |
| 1908 | Divide(remainder.reg, quotient.reg, T, a.reg, aSize, b.reg, bSize); |
| 1909 | } |
| 1910 | |
| 1911 | void Integer::Divide(Integer &remainder, Integer "ient, const Integer ÷nd, const Integer &divisor) |
| 1912 | { |
no test coverage detected