-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
define machine epsilon constants #9
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,18 @@ private MathTools() { | |
* false-positive equivalence with very small inputs. | ||
*/ | ||
public static final float FLOAT_ROUNDING_ERROR = 0x1p-20f; // was 0.000001f | ||
|
||
/** | ||
* The smallest measurable difference between a given {@code float} value and a directly adjacent value. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is right; the smallest measurable difference varies a lot based on the magnitude of the floats, and would be measured as one ulp. This is, however, the smallest non-zero distance possible between two floats returned by |
||
* Useful for converting a 64-bit {@code long} value to a gradient between 0 and 1. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also a bit of a nit-pick here, this is useful for converting non-negative up-to-24-bit |
||
*/ | ||
public static final float EPSILON = 0x1p-24f; | ||
|
||
/** | ||
* The smallest measurable difference between a given {@code double} value and a directly adjacent value. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also the comment about an ulp above applies here. This might be the smallest non-zero distance possible between two doubles returned by |
||
* Useful for converting a 64-bit {@code long} value to a gradient between 0 and 1. | ||
*/ | ||
public static final double EPSILON_D = 0x1p-53; | ||
|
||
/** | ||
* The {@code float} value that is closer than any other to | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's interesting that the multiplier used to produce the most valid zero-to-one floats with uniform spacing is also the machine epsilon; I am guessing that this isn't a coincidence.