diff --git a/condition.go b/condition.go index fdf8357..2c6e034 100644 --- a/condition.go +++ b/condition.go @@ -152,15 +152,15 @@ func (r Condition) String() string { // negateOverflowFlags converts Overflow and SystemOverflow flags into their // equivalent Underflows. -func (c Condition) negateOverflowFlags() Condition { - if c.Overflow() { +func (r Condition) negateOverflowFlags() Condition { + if r.Overflow() { // Underflow always also means Subnormal. See GDA definition. - c |= Underflow | Subnormal - c &= ^Overflow + r |= Underflow | Subnormal + r &= ^Overflow } - if c.SystemOverflow() { - c |= SystemUnderflow - c &= ^SystemOverflow + if r.SystemOverflow() { + r |= SystemUnderflow + r &= ^SystemOverflow } - return c + return r } diff --git a/context.go b/context.go index 28524f1..0df8b86 100644 --- a/context.go +++ b/context.go @@ -984,11 +984,11 @@ func (c *Context) Exp(d, x *Decimal) (Condition, error) { if err != nil { return 0, errors.Wrap(err, "ki") } - if ires, err := nc.integerPower(d, sum, ki); err != nil { + ires, err := nc.integerPower(d, sum, ki) + if err != nil { return 0, errors.Wrap(err, "integer power") - } else { - res |= ires } + res |= ires nc.Precision = c.Precision res |= nc.round(d, d) return c.goError(res) diff --git a/decimal.go b/decimal.go index 23d2b14..f0e0aca 100644 --- a/decimal.go +++ b/decimal.go @@ -38,17 +38,21 @@ type Decimal struct { Coeff big.Int } +// Form specifies the form of a Decimal. type Form int const ( // These constants must be in the following order. CmpTotal assumes that // the order of these constants reflects the total order on decimals. + // Finite is the finite form. Finite Form = iota + // Infinite is the infinite form. Infinite - // NaNSignaling will always raise the InvalidOperation condition during - // an operation. + // NaNSignaling is the signaling NaN form. It will always raise the + // InvalidOperation condition during an operation. NaNSignaling + // NaN is the NaN form. NaN ) @@ -600,9 +604,8 @@ func (d *Decimal) Cmp(x *Decimal) int { if d.Form == Infinite { if x.Form == Infinite { return 0 - } else { - return gt } + return gt } else if x.Form == Infinite { return lt } diff --git a/doc.go b/doc.go index b0dc085..649b517 100644 --- a/doc.go +++ b/doc.go @@ -12,7 +12,8 @@ // implied. See the License for the specific language governing // permissions and limitations under the License. -/* Package apd implements arbitrary-precision decimals. +/* +Package apd implements arbitrary-precision decimals. apd implements much of the decimal specification from the General Decimal Arithmetic (http://speleotrove.com/decimal/) description. This