Skip to content
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

Added float/double literals for sqrt 2/3/5 #8

Merged
merged 2 commits into from
Aug 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/main/java/com/github/tommyettinger/digital/MathTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,50 @@ private MathTools() {
*/
public static final float E = 2.7182818284590452354f;

/**
* The {@code float} value that is closer than any other to
* {@code Math.sqrt(2.0)}, the ratio of the hypotenuse of an
* isosceles right triangle to one of its legs.
*/
public static final float ROOT2 = 1.4142135623730950488f;

/**
* The {@code double} value that is closer than any other to
* {@code Math.sqrt(2.0)}, the ratio of the hypotenuse of an
* isosceles right triangle to one of its legs.
*/
public static final double ROOT2_D = 1.4142135623730950488;

/**
* The {@code float} value that is closer than any other to
* {@code Math.sqrt(3.0)}, the ratio of the diagonal length
* of a cube to its edge length.
*/
public static final float ROOT3 = 1.7320508075688772935f;

/**
* The {@code double} value that is closer than any other to
* {@code Math.sqrt(3.0)}, the ratio of the diagonal length
* of a cube to its edge length.
*/
public static final double ROOT3_D = 1.7320508075688772935;

/**
* The {@code float} value that is closer than any other to
* {@code Math.sqrt(5.0)}, which has various useful properties,
* such as appearing in many formulae involving the golden ratio
* which is of course chiefly due to being part of its calculation.
*/
public static final float ROOT5 = 2.2360679774997896964f;

/**
* The {@code double} value that is closer than any other to
* {@code Math.sqrt(5.0)}, which has various useful properties,
* such as appearing in many formulae involving the golden ratio
* which is of course chiefly due to being part of its calculation.
*/
public static final double ROOT5_D = 2.2360679774997896964;

/**
* The famous golden ratio, {@code (1.0 + Math.sqrt(5.0)) * 0.5}; this is the "most irrational" of irrational
* numbers, and has various useful properties.
Expand Down