Comments (6)
Ok so i looked up where you guys found the implementation for this function and the original author thinks that it's ok that pure 0 isn't equal to something very very close to zero.
assertFalse(nearlyEqual(0.00000001f, 0.0f));
assertFalse(nearlyEqual(0.0f, 0.00000001f));
assertFalse(nearlyEqual(-0.00000001f, 0.0f));
assertFalse(nearlyEqual(0.0f, -0.00000001f));
Personally I can't agree with that but I don't want to change the lib if you guys think so.
from mathgl.
UPDATE: ok i digged in deeper and realised that epsilon passed to FloatEqualThreshold isnt the max difference between a and b. This should be mentioned and it should be clear how it scales with numbers.
from mathgl.
Also, the declaration in java is
public static boolean nearlyEqual(float a, float b, float epsilon) {
final float absA = Math.abs(a);
final float absB = Math.abs(b);
final float diff = Math.abs(a - b);
if (a == b) { // shortcut, handles infinities
return true;
} else if (a == 0 || b == 0 || diff < Float.MIN_NORMAL) {
// a or b is zero or both are extremely close to it
// relative error is less meaningful here
return diff < (epsilon * Float.MIN_NORMAL);
} else { // use relative error
return diff / Math.min((absA + absB), Float.MAX_VALUE) < epsilon;
}
}
while ours is
func FloatEqualThreshold(a, b, epsilon float32) bool {
if a == b { // Handles the case of inf or shortcuts the loop when no significant error has accumulated
return true
}
diff := Abs(a - b)
if a*b == 0 || diff < MinNormal { // If a or b are 0 or both are extremely close to it
return diff < epsilon*epsilon
}
// Else compare difference
return diff/(Abs(a)+Abs(b)) < epsilon
}
Any reason we do epsilon*epsilon
instead of epsilon*MinNormal
?
from mathgl.
We should add a function that takes a target float, a "biggest difference" and returns a epsilon
from mathgl.
@hydroflame I haven't read everything here -- but you may be looking for relative equality, e.g. https://github.com/azul3d/lmath/blob/master/math.go#L12-L22 (http://realtimecollisiondetection.net/blog/?p=89)
from mathgl.
Yeah we still need a clearer documentation
from mathgl.
Related Issues (20)
- Error while trying to get library: undefined: sync.Pool HOT 5
- Usage with OpenGL HOT 4
- Matrix multiplication MulNx1 is incorrect HOT 2
- how to convert glm to mgl32? HOT 7
- default Epsilon and MinNormal same for both mathgl32 and mathgl64 HOT 4
- Possible copy & paste errors in tests HOT 2
- mgl32.Project lacks perspective divide HOT 1
- Request for a "Get Started" Tutorial HOT 2
- Incorrect coordinate mapping in ScreenToGLCoords and GLToScreenCoords. HOT 2
- possible error in BezierCurve2D()? HOT 2
- Go modules-compatible version tags HOT 10
- Vulkan compatibility HOT 4
- Package broken with Go 1.13 HOT 3
- Performance of basic vector math operations could be up to a 100 times faster. HOT 9
- `mgl64.Round(0, 2)` returns `-0` HOT 1
- No glm::translate and glm::scale? HOT 1
- mgl64.Vec2 does not support indexing
- Add common method for number of colums and rows HOT 1
- Add Scale() method HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mathgl.