Skip to content

RoundCeil(0.002, -1) != 0.1 #140

Description

@milan-enclave

When doing RoundCeiling operation to 0.002 with precision set to -1, we get 0 instead of 0.1.
However for RoundCeiling(1.002, -1) we get 1.1.

func TestDecimal_RoundCeil_Bug(t *testing.T) {
	var num apd.Decimal
	_, _, err := num.SetString("0.002")
	if err != nil {
		t.Fatal(err)
	}
	ctx := apd.Context{
		Precision:   100,
		Rounding:    apd.RoundCeiling,
		MaxExponent: 1000,
		MinExponent: -1000,
		Traps:       apd.DefaultTraps,
	}
	_, err = ctx.Quantize(&num, &num, -1)
	if err != nil {
		t.Fatal(err)
	}
	if num.String() != "0.1" {
		t.Errorf("Expected 0.1, got %s", num.String())
	}
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions