MCPcopy Create free account
hub / github.com/cockroachdb/apd / CmpTotal

Method CmpTotal

decimal.go:450–490  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

448// NaNSignaling
449// NaN
450func (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
492func (d *Decimal) cmpOrder() int {
493 v := int(d.Form) + 1

Callers 5

gdaTestFunction · 0.95
TestJSONEncodingFunction · 0.95
RunMethod · 0.80
TestNewWithBigIntFunction · 0.80
TestModfFunction · 0.80

Calls 3

cmpOrderMethod · 0.95
CmpMethod · 0.95
CmpMethod · 0.45

Tested by 5

gdaTestFunction · 0.76
TestJSONEncodingFunction · 0.76
RunMethod · 0.64
TestNewWithBigIntFunction · 0.64
TestModfFunction · 0.64