mirror of
https://github.com/shopspring/decimal.git
synced 2024-11-26 22:15:08 +01:00
Compare commits
2 commits
272771bd2c
...
ab39525031
Author | SHA1 | Date | |
---|---|---|---|
|
ab39525031 | ||
|
cd5465e26b |
2 changed files with 74 additions and 1 deletions
|
@ -2149,7 +2149,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()
|
||||
|
@ -2332,3 +2332,9 @@ func (d Decimal) Tan() Decimal {
|
|||
}
|
||||
return y
|
||||
}
|
||||
|
||||
//PiNumber Returns Pi Number For Calculations
|
||||
func PiNumber() Decimal {
|
||||
pi, _ := NewFromString("3.14159265358979323846264338327950288419716939937510582097494459")
|
||||
return pi
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in a new issue