- Home /
What is the kEpsilon field on Vectors?
I have built a run-time property inspector for a user customizable GUi system.
To my surprise an undocumented field showed up on all my Vector2 structs called "kEpsilon".
What is this, why is it undocumented, and is there a way to tell that I should be hiding this from my users? (or maybe I shouldn't?)
Epsilon is used in floating point math to describe the smallest increment that can be represented by the floating point type around a given number (0.0f in C#, 1.0 in C++). Single floats in C# are 8 bit exponent and 23 bit mantissa, and Single.Epsilon is the magnitude of change in value incurred by changing the mantissa by 1 when the exponent is -126. It's a measure of the accuracy of the floating point representation but it only holds for floats with the same exponent, so it's not a true measure of precision.
Given that background (which you may or may not know!) I'd say that kEpsilon is some measure of the smallest representable Vector2. It is probably used in some capacity by the == operator, especially as the Unity docs for Vector2.== state that it returns true for Vectors that are very close, but not quite, equal.
Thanks. Thats helpful. I remembered from math tag Epsilons have to do with $$anonymous$$ima values but thats it.
Im still trying to figure out how to hide it. k may mean its a constant so maybe I can detect it that way...
Answer by KrankyBoy · Oct 14, 2018 at 05:26 PM
It can be used when comparing two vectors. Since they are floats it is hard to get them exactly equal. An example would be moving an object from one position to another. You can check the distance between then objects and then if they are closer than kEpsilon then they are equal.
Answer by greggman · Nov 30, 2014 at 10:20 PM
It's static according to
Vector2 v = new Vector2(2f,3f);
System.Reflection.FieldInfo[] fields = v.GetType().GetFields();
foreach (System.Reflection.FieldInfo info in fields) {
Debug.Log(info.Name + (info.IsStatic ? " static " : ""));
}
Your answer
Follow this Question
Related Questions
C# Convert Vector3[] to Vector2[] 3 Answers
Create custom constructors for certain Value types/Objects (Vector3, Transform, etc...) 2 Answers
[HELP] Translating vector 2 co-ordinates to real space 1 Answer
What happens when I populate a ray with a vector2? 1 Answer
how to find a point(vector2) between two points(Vector2) of a line (line renderer) 2 Answers