Documentation ¶
Index ¶
- Constants
- Variables
- type Frac
- func Abs(f *Frac) *Frac
- func Add(a, b *Frac) *Frac
- func AddInt(f *Frac, x int) *Frac
- func Cos(f *Frac) *Frac
- func Div(a, b *Frac) (*Frac, error)
- func DivInt(f *Frac, x int) (*Frac, error)
- func Mul(a, b *Frac) (*Frac, error)
- func MulInt(f *Frac, x int) (*Frac, error)
- func MustNew(num, dom int64) *Frac
- func New(num, dom int64) (*Frac, error)
- func NewFromFloat64(f float64, maxIterations int) *Frac
- func NewFromInt(num int) *Frac
- func NewFromInt64(num int64) *Frac
- func NewFromRat(rat *big.Rat) *Frac
- func NewFromString(exp string) (*Frac, error)
- func NewZero() *Frac
- func Sin(f *Frac) *Frac
- func Sqrt(f *Frac) *Frac
- func Square(f *Frac) *Frac
- func Sub(a, b *Frac) *Frac
- func SubInt(f *Frac, x int) *Frac
- func (f *Frac) Abs()
- func (f *Frac) Add(x *Frac)
- func (f *Frac) AddInt(x int)
- func (f *Frac) AddInt64(x int64)
- func (f *Frac) Copy() *Frac
- func (f *Frac) Div(x *Frac)
- func (f *Frac) DivInt(x int)
- func (f *Frac) Equal(b *Frac) bool
- func (f *Frac) ExactFloat64() bool
- func (f *Frac) Float64() float64
- func (f *Frac) GreaterThan(b *Frac) bool
- func (f *Frac) Int() int
- func (f *Frac) Int64() int64
- func (f *Frac) IsZero() bool
- func (f *Frac) LessThan(b *Frac) bool
- func (f *Frac) Mul(x *Frac)
- func (f *Frac) MulInt(x int)
- func (f *Frac) Rat() *big.Rat
- func (f *Frac) Round() int
- func (f *Frac) SetExact(exact bool)
- func (f *Frac) SetMaxReduceIterations(maxReduceIterations int)
- func (f *Frac) Splitup() (int64, *Frac)
- func (f *Frac) Sqrt()
- func (f *Frac) Square()
- func (f *Frac) String() string
- func (f *Frac) Sub(x *Frac)
- func (f *Frac) SubInt(x int)
- func (f *Frac) SubInt64(x int64)
Examples ¶
Constants ¶
const ( // DefaultMaxIterations is the default value of iterations when converting a float to a fractional number. DefaultMaxIterations = 400 // Inifinite iterations I = -1 // A large number of iterations L = 9999 )
Variables ¶
var ( Zero = &Frac{0, 1, DefaultMaxIterations, true} One = &Frac{1, 1, DefaultMaxIterations, true} ErrDivByZero = errors.New("division by zero") )
Functions ¶
This section is empty.
Types ¶
type Frac ¶
type Frac struct {
// contains filtered or unexported fields
}
func MustNew ¶
MustNew must create a new fractional number. If it is not possible, no error will be returned and it will panic.
func New ¶
New creates a new fractional number. Takes a numinator and a denominator. The maximum number of iterations that should be used for reducing the fraction during calculations is set to the default value.
func NewFromFloat64 ¶
Try to convert a float to a fraction Takes a float and a maximum number of iterations to find the fraction The maximum number of iterations can be -1 to iterate as much as necessary Returns a bool that is True if the maximum number of iterations has not been reached
func NewFromRat ¶
Creates a new fraction from a rational number (big.Rat)
func NewFromString ¶
Creates a new fraction from a string on the form "N/D", where N is the numerator and D is the denominator. For example: "1/2" or "3/8".
func Sqrt ¶
Sqrt returns the square root of the number
Example ¶
x := NewFromInt(9) fmt.Println(Sqrt(x).Float64())
Output: 3
func (*Frac) Equal ¶
Quickly check if one fraction is equal to the other, by only multiplying and comparing
func (*Frac) ExactFloat64 ¶
func (*Frac) GreaterThan ¶
Quickly check if one fraction is larger than the other, by only multiplying and comparing
func (*Frac) LessThan ¶
Quickly check if one fraction is less than the other, by only multiplying and comparing
func (*Frac) SetMaxReduceIterations ¶
Change the maximum number of iterations that should be used for reductions