setAsNaN sets d to the first NaNSignaling, or otherwise first NaN, of x and y. x is required, y is optional. Expects one of the two inputs to be NaN.
(d *Decimal, x, y *Decimal)
| 105 | // x and y. x is required, y is optional. Expects one of the two inputs |
| 106 | // to be NaN. |
| 107 | func (c *Context) setAsNaN(d *Decimal, x, y *Decimal) (Condition, error) { |
| 108 | var nan *Decimal |
| 109 | // Per the method contract, NaNSignaling takes precedence over NaN. |
| 110 | if x.Form == NaNSignaling { |
| 111 | nan = x |
| 112 | } else if y != nil && y.Form == NaNSignaling { |
| 113 | nan = y |
| 114 | } else if x.Form == NaN { |
| 115 | nan = x |
| 116 | } else if y != nil && y.Form == NaN { |
| 117 | nan = y |
| 118 | } else { |
| 119 | return 0, errors.New("no NaN value found; was shouldSetAsNaN called?") |
| 120 | } |
| 121 | d.Set(nan) |
| 122 | var res Condition |
| 123 | if nan.Form == NaNSignaling { |
| 124 | res = InvalidOperation |
| 125 | d.Form = NaN |
| 126 | } |
| 127 | _, err := c.goError(res) |
| 128 | return res, err |
| 129 | } |
| 130 | |
| 131 | func (c *Context) add(d, x, y *Decimal, subtract bool) (Condition, error) { |
| 132 | if c.shouldSetAsNaN(x, y) { |
no test coverage detected