CmpTotal compares d and x using their abstract representation rather than their numerical value. A total ordering is defined for all possible abstract representations, as described below. If the first operand is lower in the total order than the second operand then the result is -1, if the operands
(x *Decimal)
| 448 | // NaNSignaling |
| 449 | // NaN |
| 450 | func (d *Decimal) CmpTotal(x *Decimal) int { |
| 451 | do := d.cmpOrder() |
| 452 | xo := x.cmpOrder() |
| 453 | |
| 454 | if do < xo { |
| 455 | return -1 |
| 456 | } |
| 457 | if do > xo { |
| 458 | return 1 |
| 459 | } |
| 460 | |
| 461 | switch d.Form { |
| 462 | case Finite: |
| 463 | // d and x have the same sign and form, compare their value. |
| 464 | if c := d.Cmp(x); c != 0 { |
| 465 | return c |
| 466 | } |
| 467 | |
| 468 | lt := -1 |
| 469 | gt := 1 |
| 470 | if d.Negative { |
| 471 | lt = 1 |
| 472 | gt = -1 |
| 473 | } |
| 474 | |
| 475 | // Values are equal, compare exponents. |
| 476 | if d.Exponent < x.Exponent { |
| 477 | return lt |
| 478 | } |
| 479 | if d.Exponent > x.Exponent { |
| 480 | return gt |
| 481 | } |
| 482 | return 0 |
| 483 | |
| 484 | case Infinite: |
| 485 | return 0 |
| 486 | |
| 487 | default: |
| 488 | return d.Coeff.Cmp(&x.Coeff) |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | func (d *Decimal) cmpOrder() int { |
| 493 | v := int(d.Form) + 1 |