Git Product home page Git Product logo

fixed's People

Contributors

andviro avatar deepsourcebot avatar kardianos avatar robaho avatar shalakhin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fixed's Issues

Use integer math for Mul

The Mul() uses float64 math. It’s not typically a problem with the rounding at the 8th place bue using integer math should be more accurate an possible faster.

NewSErr panic

fixed.NewSErr("123.1234567891")
panic: runtime error: slice bounds out of range

Rename NewSErr to Parse

Rename NewSErr to Parse, NewS to MustParse to follow stdlib style (see package text/template).

Question regarding rounding implementation

I'm rewriting some code from python to go and using this excellent library.

As I understand this library implements rounding using ROUND_HALF_UP algorithm, but I've noticed that sometimes this library rounds numbers differently from python's decimal package, see example:

fmt.Printf("%s\n", fixed.MustParse("2234.565").Round(2).String()) // 2234.56
print(decimal.Decimal("2234.565").quantize(decimal.Decimal("0.01"), rounding=decimal.ROUND_HALF_UP)) # 2234.57

So, for input 2234.565 fixed's output is 2234.56, while python's output is 2234.57.

Is .56 result correct? I think rounding away from zero should give us .57.

Also could you please clarify that ROUND_HALF_UP from python should match this library's version? Or maybe I'm wrong and should be comparing this library to some other python rounding mode (https://docs.python.org/3/library/decimal.html#rounding-modes). I assume I should be comparing against ROUND_HALF_UP because fixed's source code says so:

// Round returns a rounded (half-up, away from zero) to n decimal places
func (f Fixed) Round(n int) Fixed {

JSON encoding of NaN

JSON encoding of NaN numbers doesn't work:

func (f Fixed) MarshalJSON() ([]byte, error) {
buffer := make([]byte, 24)
return itoa(buffer, f.fp), nil
}

why go get -u github.com/robaho/fixed ERROR

> go get -u -v github.com/robaho/fixed
github.com/robaho/fixed (download)
github.com/robaho/fixed
# github.com/robaho/fixed
D:\MyProgram\Go\src\github.com\robaho\fixed\decomposer.go:62:19: invalid operation: uint64(v) << (i * 8) (shift count type int, must be unsigned integer)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.