(self)
| 1761 | |
| 1762 | @requires_IEEE_754 |
| 1763 | def testRemainder(self): |
| 1764 | from fractions import Fraction |
| 1765 | |
| 1766 | def validate_spec(x, y, r): |
| 1767 | """ |
| 1768 | Check that r matches remainder(x, y) according to the IEEE 754 |
| 1769 | specification. Assumes that x, y and r are finite and y is nonzero. |
| 1770 | """ |
| 1771 | fx, fy, fr = Fraction(x), Fraction(y), Fraction(r) |
| 1772 | # r should not exceed y/2 in absolute value |
| 1773 | self.assertLessEqual(abs(fr), abs(fy/2)) |
| 1774 | # x - r should be an exact integer multiple of y |
| 1775 | n = (fx - fr) / fy |
| 1776 | self.assertEqual(n, int(n)) |
| 1777 | if abs(fr) == abs(fy/2): |
| 1778 | # If |r| == |y/2|, n should be even. |
| 1779 | self.assertEqual(n/2, int(n/2)) |
| 1780 | |
| 1781 | # triples (x, y, remainder(x, y)) in hexadecimal form. |
| 1782 | testcases = [ |
| 1783 | # Remainders modulo 1, showing the ties-to-even behaviour. |
| 1784 | '-4.0 1 -0.0', |
| 1785 | '-3.8 1 0.8', |
| 1786 | '-3.0 1 -0.0', |
| 1787 | '-2.8 1 -0.8', |
| 1788 | '-2.0 1 -0.0', |
| 1789 | '-1.8 1 0.8', |
| 1790 | '-1.0 1 -0.0', |
| 1791 | '-0.8 1 -0.8', |
| 1792 | '-0.0 1 -0.0', |
| 1793 | ' 0.0 1 0.0', |
| 1794 | ' 0.8 1 0.8', |
| 1795 | ' 1.0 1 0.0', |
| 1796 | ' 1.8 1 -0.8', |
| 1797 | ' 2.0 1 0.0', |
| 1798 | ' 2.8 1 0.8', |
| 1799 | ' 3.0 1 0.0', |
| 1800 | ' 3.8 1 -0.8', |
| 1801 | ' 4.0 1 0.0', |
| 1802 | |
| 1803 | # Reductions modulo 2*pi |
| 1804 | '0x0.0p+0 0x1.921fb54442d18p+2 0x0.0p+0', |
| 1805 | '0x1.921fb54442d18p+0 0x1.921fb54442d18p+2 0x1.921fb54442d18p+0', |
| 1806 | '0x1.921fb54442d17p+1 0x1.921fb54442d18p+2 0x1.921fb54442d17p+1', |
| 1807 | '0x1.921fb54442d18p+1 0x1.921fb54442d18p+2 0x1.921fb54442d18p+1', |
| 1808 | '0x1.921fb54442d19p+1 0x1.921fb54442d18p+2 -0x1.921fb54442d17p+1', |
| 1809 | '0x1.921fb54442d17p+2 0x1.921fb54442d18p+2 -0x0.0000000000001p+2', |
| 1810 | '0x1.921fb54442d18p+2 0x1.921fb54442d18p+2 0x0p0', |
| 1811 | '0x1.921fb54442d19p+2 0x1.921fb54442d18p+2 0x0.0000000000001p+2', |
| 1812 | '0x1.2d97c7f3321d1p+3 0x1.921fb54442d18p+2 0x1.921fb54442d14p+1', |
| 1813 | '0x1.2d97c7f3321d2p+3 0x1.921fb54442d18p+2 -0x1.921fb54442d18p+1', |
| 1814 | '0x1.2d97c7f3321d3p+3 0x1.921fb54442d18p+2 -0x1.921fb54442d14p+1', |
| 1815 | '0x1.921fb54442d17p+3 0x1.921fb54442d18p+2 -0x0.0000000000001p+3', |
| 1816 | '0x1.921fb54442d18p+3 0x1.921fb54442d18p+2 0x0p0', |
| 1817 | '0x1.921fb54442d19p+3 0x1.921fb54442d18p+2 0x0.0000000000001p+3', |
| 1818 | '0x1.f6a7a2955385dp+3 0x1.921fb54442d18p+2 0x1.921fb54442d14p+1', |
| 1819 | '0x1.f6a7a2955385ep+3 0x1.921fb54442d18p+2 0x1.921fb54442d18p+1', |
| 1820 | '0x1.f6a7a2955385fp+3 0x1.921fb54442d18p+2 -0x1.921fb54442d14p+1', |
nothing calls this directly
no test coverage detected