This commit is contained in:
Ali J. Alaee 2022-04-29 12:09:20 +09:00 committed by GitHub
commit 6f843cac49
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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 { func (d Decimal) satan() Decimal {
Morebits := NewFromFloat(6.123233995736765886130e-17) // pi/2 = PIO2 + Morebits Morebits := NewFromFloat(6.123233995736765886130e-17) // pi/2 = PIO2 + Morebits
Tan3pio8 := NewFromFloat(2.41421356237309504880) // tan(3*pi/8) Tan3pio8 := NewFromFloat(2.41421356237309504880) // tan(3*pi/8)
pi := NewFromFloat(3.14159265358979323846264338327950288419716939937510582097494459) pi := PiNumber()
if d.LessThanOrEqual(NewFromFloat(0.66)) { if d.LessThanOrEqual(NewFromFloat(0.66)) {
return d.xatan() return d.xatan()
@ -1902,3 +1902,9 @@ func (d Decimal) Tan() Decimal {
} }
return y 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) { func TestNewFromFloatQuick(t *testing.T) {
err := quick.Check(func(f float64) bool { err := quick.Check(func(f float64) bool {
want, werr := NewFromString(strconv.FormatFloat(f, 'f', -1, 64)) want, werr := NewFromString(strconv.FormatFloat(f, 'f', -1, 64))