math_plus

package
v0.0.0-...-2946602 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 6, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const DIV_SYMBOL = "/"

Variables

View Source
var One = Fraction{
	// contains filtered or unexported fields
}
View Source
var (
	ZERO_DENOMINATOR = errors.New("Denominator is 0 ! ")
)
View Source
var Zero = Fraction{
	// contains filtered or unexported fields
}

Functions

func AnyToTen

func AnyToTen(num string, n int) int

AnyToTen 任意进制转10进制

func GreatestCommonDivisor

func GreatestCommonDivisor(x, y int64) int64

GreatestCommonDivisor 最大公约数:(辗转相除法)

func LeastCommonMultiple

func LeastCommonMultiple(x, y int64) int64

LeastCommonMultiple 最小公倍数:((x*y)/最大公约数)

func TenToAny

func TenToAny(num, n int) string

func TenToAnyWithMapping

func TenToAnyWithMapping(num, n int, mapping map[int]string) string

TenToAnyWithMapping 10进制转任意进制 num 10进制数 n 几进制 mapping 映射表

Types

type Fraction

type Fraction struct {
	// contains filtered or unexported fields
}

Fraction 分数

func FloatToFraction

func FloatToFraction(f float64) (Fraction, error)

func New

func New(n, d int64) (Fraction, error)

New 创建假分数

func NewFromFloat

func NewFromFloat(n, d float64) (Fraction, error)

NewFromFloat 从小数创建

func NewFromFloatByDecimal

func NewFromFloatByDecimal(n, d float64) Fraction

NewFromFloatByDecimal 使用decimal 计算,结果可能不完全正确

func NewFromString

func NewFromString(str string) (Fraction, error)

NewFromString 从字符串创建,字符串中分子分母需为整数

支持 int/int  int float

func (Fraction) Add

func (f Fraction) Add(fra Fraction) Fraction

Add 加

func (Fraction) Div

func (f Fraction) Div(fra Fraction) Fraction

Div 除

func (Fraction) Float64

func (f Fraction) Float64() float64

Float64 格式化输出

func (Fraction) IsZero

func (f Fraction) IsZero() bool

func (Fraction) Mul

func (f Fraction) Mul(fra Fraction) Fraction

Mul 乘

func (Fraction) MulInt64

func (f Fraction) MulInt64(n int64) Fraction

func (Fraction) Reverse

func (f Fraction) Reverse() Fraction

Reverse 倒数

func (Fraction) String

func (f Fraction) String() string

String 格式化输出

func (Fraction) Sub

func (f Fraction) Sub(fra Fraction) Fraction

Sub 减

func (Fraction) ToFakeFraction

func (f Fraction) ToFakeFraction(multiple int64) Fraction

ToFakeFraction 真分数扩大

func (Fraction) ToRealFraction

func (f Fraction) ToRealFraction() Fraction

ToRealFraction 约分

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL