diff --git a/decimal.go b/decimal.go index c614ea7..378101e 100644 --- a/decimal.go +++ b/decimal.go @@ -1719,7 +1719,7 @@ func (d Decimal) xatan() Decimal { func (d Decimal) satan() Decimal { Morebits := NewFromFloat(6.123233995736765886130e-17) // pi/2 = PIO2 + Morebits Tan3pio8 := NewFromFloat(2.41421356237309504880) // tan(3*pi/8) - pi := NewFromFloat(3.14159265358979323846264338327950288419716939937510582097494459) + pi := PiNumber() if d.LessThanOrEqual(NewFromFloat(0.66)) { return d.xatan() @@ -1902,3 +1902,9 @@ func (d Decimal) Tan() Decimal { } return y } + +//PiNumber Returns Pi Number For Calculations +func PiNumber() Decimal { + pi, _ := NewFromString("3.14159265358979323846264338327950288419716939937510582097494459") + return pi +} diff --git a/decimal_test.go b/decimal_test.go index 2b3a99e..3a7fd79 100644 --- a/decimal_test.go +++ b/decimal_test.go @@ -153,6 +153,73 @@ func TestNewFromFloatRandom(t *testing.T) { } } +func TestPiNumber(t *testing.T) { + a := PiNumber() + b := New(-1234, 2) + + if a.Cmp(b) != 1 { + t.Errorf("Error") + } +} + +func TestPiNumberE(t *testing.T) { + a := PiNumber() + b := New(1274, 3) + c := New(1234, 4) + + if a.Equal(b) { + t.Errorf("%q should equal %q", a, b) + } + if a.Equal(c) { + t.Errorf("%q should not equal %q", a, c) + } + + // note, this block should be deprecated, here for backwards compatibility + if a.Equals(b) { + t.Errorf("%q should equal %q", a, b) + } + + if !c.GreaterThan(b) { + t.Errorf("%q should be greater than %q", c, b) + } + if b.GreaterThan(c) { + t.Errorf("%q should not be greater than %q", b, c) + } + if a.GreaterThanOrEqual(b) { + t.Errorf("%q should be greater or equal %q", a, b) + } + if !c.GreaterThanOrEqual(b) { + t.Errorf("%q should be greater or equal %q", c, b) + } + if b.GreaterThanOrEqual(c) { + t.Errorf("%q should not be greater or equal %q", b, c) + } + if !b.LessThan(c) { + t.Errorf("%q should be less than %q", a, b) + } + if c.LessThan(b) { + t.Errorf("%q should not be less than %q", a, b) + } + if !a.LessThanOrEqual(b) { + t.Errorf("%q should be less than or equal %q", a, b) + } + if !b.LessThanOrEqual(c) { + t.Errorf("%q should be less than or equal %q", a, b) + } + if c.LessThanOrEqual(b) { + t.Errorf("%q should not be less than or equal %q", a, b) + } +} + +func TestDpi_Cmp(t *testing.T) { + a := PiNumber() + b := PiNumber() + + if a.Cmp(b) == -1 { + t.Errorf("Error") + } +} + func TestNewFromFloatQuick(t *testing.T) { err := quick.Check(func(f float64) bool { want, werr := NewFromString(strconv.FormatFloat(f, 'f', -1, 64))