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