(appendTo []byte, d *apd.Decimal, invert bool)
| 52 | } |
| 53 | |
| 54 | func encodeDecimal(appendTo []byte, d *apd.Decimal, invert bool) []byte { |
| 55 | if d.IsZero() { |
| 56 | // Negative and positive zero are encoded identically. Only nonsorting |
| 57 | // decimal encoding can retain the sign. |
| 58 | return append(appendTo, decimalZero) |
| 59 | } |
| 60 | neg := d.Negative != invert |
| 61 | switch d.Form { |
| 62 | case apd.Finite: |
| 63 | // ignore |
| 64 | case apd.Infinite: |
| 65 | if neg { |
| 66 | return append(appendTo, decimalNegativeInfinity) |
| 67 | } |
| 68 | return append(appendTo, decimalInfinity) |
| 69 | case apd.NaN: |
| 70 | if invert { |
| 71 | return append(appendTo, decimalNaNDesc) |
| 72 | } |
| 73 | return append(appendTo, decimalNaN) |
| 74 | default: |
| 75 | panic(errors.Errorf("unknown form: %s", d.Form)) |
| 76 | } |
| 77 | e, m := decimalEandM(d, appendTo[len(appendTo):]) |
| 78 | return encodeEandM(appendTo, neg, e, m) |
| 79 | } |
| 80 | |
| 81 | // decimalEandM computes and returns the exponent E and mantissa M for d. |
| 82 | // |
no test coverage detected
searching dependent graphs…