Compare commits

...

2 commits

Author SHA1 Message Date
Ali J. Alaee
6f843cac49
Merge cd5465e26b into f55dd56454 2022-04-29 12:09:20 +09:00
Ali
cd5465e26b PiNumber() implemented (with tests) issue #185 2021-02-05 20:07:12 +03:30
2 changed files with 74 additions and 1 deletions

View file

@ -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
}

View file

@ -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))