Compose sets the internal decimal value from parts. If the value cannot be represented then an error should be returned.
(form byte, negative bool, coefficient []byte, exponent int32)
| 92 | // Compose sets the internal decimal value from parts. If the value cannot be |
| 93 | // represented then an error should be returned. |
| 94 | func (d *Decimal) Compose(form byte, negative bool, coefficient []byte, exponent int32) error { |
| 95 | switch form { |
| 96 | default: |
| 97 | return fmt.Errorf("unknown form: %v", form) |
| 98 | case 0: |
| 99 | d.Form = Finite |
| 100 | // Set rest of finite form below. |
| 101 | case 1: |
| 102 | d.Form = Infinite |
| 103 | d.Negative = negative |
| 104 | return nil |
| 105 | case 2: |
| 106 | d.Form = NaN |
| 107 | d.Negative = negative |
| 108 | return nil |
| 109 | } |
| 110 | // Finite form. |
| 111 | d.Negative = negative |
| 112 | d.Coeff.SetBytes(coefficient) |
| 113 | d.Exponent = exponent |
| 114 | return nil |
| 115 | } |