(self, exact, rounded)
| 431 | raise ValueError("Unexpected rounding mode: %s" % mode) |
| 432 | |
| 433 | def check_ulpdiff(self, exact, rounded): |
| 434 | # current precision |
| 435 | p = context.p.prec |
| 436 | |
| 437 | # Convert infinities to the largest representable number + 1. |
| 438 | x = exact |
| 439 | if exact.is_infinite(): |
| 440 | x = _dec_from_triple(exact._sign, '10', context.p.Emax) |
| 441 | y = rounded |
| 442 | if rounded.is_infinite(): |
| 443 | y = _dec_from_triple(rounded._sign, '10', context.p.Emax) |
| 444 | |
| 445 | # err = (rounded - exact) / ulp(rounded) |
| 446 | self.maxctx.prec = p * 2 |
| 447 | t = self.maxctx.subtract(y, x) |
| 448 | if context.c.flags[C.Clamped] or \ |
| 449 | context.c.flags[C.Underflow]: |
| 450 | # The standard ulp does not work in Underflow territory. |
| 451 | ulp = self.harrison_ulp(y) |
| 452 | else: |
| 453 | ulp = self.standard_ulp(y, p) |
| 454 | # Error in ulps. |
| 455 | err = self.maxctx.divide(t, ulp) |
| 456 | |
| 457 | dir = self.rounding_direction(x, context.p.rounding) |
| 458 | if dir == 0: |
| 459 | if P.Decimal("-0.6") < err < P.Decimal("0.6"): |
| 460 | return True |
| 461 | elif dir == 1: # directed, upwards |
| 462 | if P.Decimal("-0.1") < err < P.Decimal("1.1"): |
| 463 | return True |
| 464 | elif dir == -1: # directed, downwards |
| 465 | if P.Decimal("-1.1") < err < P.Decimal("0.1"): |
| 466 | return True |
| 467 | else: # ROUND_05UP |
| 468 | if P.Decimal("-1.1") < err < P.Decimal("1.1"): |
| 469 | return True |
| 470 | |
| 471 | print("ulp: %s error: %s exact: %s c_rounded: %s" |
| 472 | % (ulp, err, exact, rounded)) |
| 473 | return False |
| 474 | |
| 475 | def bin_resolve_ulp(self, t): |
| 476 | """Check if results of _decimal's power function are within the |
no test coverage detected