GithubHelp home page GithubHelp logo

Comments (1)

pwaller avatar pwaller commented on June 26, 2024 1

Nice find. Signed zero is a thing that floating point numbers have :)

https://en.wikipedia.org/wiki/Signed_zero

It looks like this is arising from the current definition of Round, which at a glance is doing 'tie breaks round towards nearest', with 'rounding towards zero'.

mathgl/mgl64/util.go

Lines 137 to 146 in 592312d

// Round shortens a float32 value to a specified precision (number of digits after the decimal point)
// with "round half up" tie-braking rule. Half-way values (23.5) are always rounded up (24).
func Round(v float64, precision int) float64 {
p := float64(precision)
t := float64(v) * math.Pow(10, p)
if t > 0 {
return float64(math.Floor(t+0.5) / math.Pow(10, p))
}
return float64(math.Ceil(t-0.5) / math.Pow(10, p))
}

The if t > 0 is false, so it's rounding as if 'zero is negative'. The sign is appearing from math.Ceil(-0.5): https://go.dev/play/p/RtDbZu9JNlF

I think the fix is to change the condition to if t >= 0 because negative zero was neglected. Patches welcome? :)

from mathgl.

Related Issues (20)

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.