diff --git a/context.go b/context.go index 28524f1..1af6dd2 100644 --- a/context.go +++ b/context.go @@ -1226,8 +1226,9 @@ func (c *Context) toIntegralSpecials(d, x *Decimal) (bool, Condition, error) { return false, 0, nil } -// ToIntegral sets d to integral value of x. Inexact and Rounded flags are ignored and removed. -func (c *Context) ToIntegral(d, x *Decimal) (Condition, error) { +// RoundToIntegralValue sets d to integral value of x. Inexact and Rounded flags +// are ignored and removed. +func (c *Context) RoundToIntegralValue(d, x *Decimal) (Condition, error) { if set, res, err := c.toIntegralSpecials(d, x); set { return res, err } @@ -1236,8 +1237,8 @@ func (c *Context) ToIntegral(d, x *Decimal) (Condition, error) { return c.goError(res) } -// ToIntegralX sets d to integral value of x. -func (c *Context) ToIntegralX(d, x *Decimal) (Condition, error) { +// RoundToIntegralExact sets d to integral value of x. +func (c *Context) RoundToIntegralExact(d, x *Decimal) (Condition, error) { if set, res, err := c.toIntegralSpecials(d, x); set { return res, err } diff --git a/error.go b/error.go index 79b7157..9dff9dc 100644 --- a/error.go +++ b/error.go @@ -177,12 +177,12 @@ func (e *ErrDecimal) Sub(d, x, y *Decimal) *Decimal { return e.op3(d, x, y, e.Ctx.Sub) } -// ToIntegral performs e.Ctx.ToIntegral(d, x) and returns d. -func (e *ErrDecimal) ToIntegral(d, x *Decimal) *Decimal { - return e.op2(d, x, e.Ctx.ToIntegral) +// RoundToIntegralValue performs e.Ctx.RoundToIntegralValue(d, x) and returns d. +func (e *ErrDecimal) RoundToIntegralValue(d, x *Decimal) *Decimal { + return e.op2(d, x, e.Ctx.RoundToIntegralValue) } -// ToIntegralX performs e.Ctx.ToIntegralX(d, x) and returns d. -func (e *ErrDecimal) ToIntegralX(d, x *Decimal) *Decimal { - return e.op2(d, x, e.Ctx.ToIntegralX) +// RoundToIntegralExact performs e.Ctx.RoundToIntegralExact(d, x) and returns d. +func (e *ErrDecimal) RoundToIntegralExact(d, x *Decimal) *Decimal { + return e.op2(d, x, e.Ctx.RoundToIntegralExact) } diff --git a/example_test.go b/example_test.go index b493987..461d445 100644 --- a/example_test.go +++ b/example_test.go @@ -101,11 +101,11 @@ func ExampleErrDecimal() { // Infinity, err: division by zero } -// ExampleToIntegralX demonstrates how to use ToIntegralX to check if a -// number is an integer or not. Note the variations between integer (which -// allows zeros after the decimal point) and strict (which does not). See +// ExampleRoundToIntegralExact demonstrates how to use RoundToIntegralExact to +// check if a number is an integer or not. Note the variations between integer +// (which allows zeros after the decimal point) and strict (which does not). See // the documentation on Inexact and Rounded. -func ExampleContext_ToIntegralX() { +func ExampleContext_RoundToIntegralExact() { inputs := []string{ "123.4", "123.0", @@ -116,19 +116,19 @@ func ExampleContext_ToIntegralX() { } for _, input := range inputs { d, _, _ := apd.NewFromString(input) - res, _ := apd.BaseContext.ToIntegralX(d, d) + res, _ := apd.BaseContext.RoundToIntegralExact(d, d) integer := !res.Inexact() strict := !res.Rounded() - fmt.Printf("input: % 6s, ToIntegralX: % 3s, integer: % 5t, strict: % 5t, res:", input, d, integer, strict) + fmt.Printf("input: % 6s, output: % 3s, integer: % 5t, strict: % 5t, res:", input, d, integer, strict) if res != 0 { fmt.Printf(" %s", res) } fmt.Println() } - // Output: input: 123.4, ToIntegralX: 123, integer: false, strict: false, res: inexact, rounded - // input: 123.0, ToIntegralX: 123, integer: true, strict: false, res: rounded - // input: 123, ToIntegralX: 123, integer: true, strict: true, res: - // input: 12E1, ToIntegralX: 120, integer: true, strict: true, res: - // input: 120E-1, ToIntegralX: 12, integer: true, strict: false, res: rounded - // input: 120E-2, ToIntegralX: 1, integer: false, strict: false, res: inexact, rounded + // Output: input: 123.4, output: 123, integer: false, strict: false, res: inexact, rounded + // input: 123.0, output: 123, integer: true, strict: false, res: rounded + // input: 123, output: 123, integer: true, strict: true, res: + // input: 12E1, output: 120, integer: true, strict: true, res: + // input: 120E-1, output: 12, integer: true, strict: false, res: rounded + // input: 120E-2, output: 1, integer: false, strict: false, res: inexact, rounded } diff --git a/gda_test.go b/gda_test.go index 544dfe6..b77b69b 100644 --- a/gda_test.go +++ b/gda_test.go @@ -276,9 +276,9 @@ func (tc TestCase) Run(c *Context, done chan error, d, x, y *Decimal) (res Condi case "subtract": res, err = c.Sub(d, x, y) case "tointegral": - res, err = c.ToIntegral(d, x) + res, err = c.RoundToIntegralValue(d, x) case "tointegralx": - res, err = c.ToIntegralX(d, x) + res, err = c.RoundToIntegralExact(d, x) // Below used only in benchmarks. Tests call it themselves. case "comparetotal":