calc

package
v2.0.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package calc enter string equations to implement numeric arithmetic

Index

Examples

Constants

View Source
const CalcAccuracy int8 = 7

Variables

This section is empty.

Functions

func FloatSimple

func FloatSimple(fv string) string

FloatSimple Floating-point number string beautification

func NumberClear

func NumberClear(s string) string

NumberClear number string clear like '_' or ','

func NumberSplitFormat

func NumberSplitFormat(n float64, bits ...int) string

NumberSplitFormat numeric value segmentation and beautification

func StringAsFloat

func StringAsFloat(s string) float64

func StringAsI64

func StringAsI64(s string) int64

Types

type Calc

type Calc struct {
	Accuracy int8
	// contains filtered or unexported fields
}

Calc String equality operator, which calculates the result of input string equality support: `**,^,*,/,+,-,%`

func CalcEq

func CalcEq(eq string) Calc

func NewCalc

func NewCalc(equality string) *Calc

NewCalc String Equation Calculation support `f8,exp` to set .Accuracy

Example
cl := NewCalc("3!+2pi")
cl.Count()
fmt.Printf("%v\n", cl.String())

// 等式中指定精度
cl = NewCalc("f17, 3!+2pi")
cl.Count()
fmt.Printf("%v\n", cl.String())

cl.Count("3-(2^2-pi)")
fmt.Printf("%v\n", cl.String())
Output:

12.2831854
12.28318530717958623
2.14159265358979312

func (*Calc) Count

func (c *Calc) Count(args ...string) float64

func (*Calc) Exp

func (c *Calc) Exp(eq string) string

Exp support functional expression e.g. sprt, log, sin, cos, tan.

Notice: Attempt to expose it to external interfaces

func (*Calc) String

func (c *Calc) String() string

Jump to

Keyboard shortcuts

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