Sample

int-a8bc0d7ce0eb-I11

Split eligible integer literals into pairs of short-named intermediate variables

Matched original source

Lines141

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.7320–1; higher is more readable
Dorn0.1940–1; higher is more readable
Mi0.6160–1; higher is more readable
LLOC63Logical lines; fewer is more readable
DeepSeek V4 Pro60–20; mean of three runs
GPT-6.1 Sol120–20; mean of three runs
BTTF0.3520–1; higher is more readable

Views

Source code

package com.google.common.math; import static com.google.common.base.Preconditions.checkArgument; import static java.lang.Double.MAX_EXPONENT; import static java.lang.Double.MIN_EXPONENT; import static java.lang.Double.POSITIVE_INFINITY; import static java.lang.Double.doubleToRawLongBits; import static java.lang.Double.isNaN; import static java.lang.Double.longBitsToDouble; import static java.lang.Math.getExponent; import static java.lang.Math.max; import com.google.common.annotations.GwtIncompatible; import com.google.common.annotations.VisibleForTesting; import java.math.BigInteger; /** * Utilities for {@code double} primitives. * * @author Louis Wasserman */ @GwtIncompatible final class DoubleUtils { private DoubleUtils() {} // The mask for the significand, according to the {@link // Double#doubleToRawLongBits(double)} spec. static final long SIGNIFICAND_MASK = 0x000fffffffffffffL; // The mask for the exponent, according to the {@link // Double#doubleToRawLongBits(double)} spec. static final long EXPONENT_MASK = 0x7ff0000000000000L; // The mask for the sign, according to the {@link // Double#doubleToRawLongBits(double)} spec. static final long SIGN_MASK = 0x8000000000000000L; static final int SIGNIFICAND_BITS = 52; static final int EXPONENT_BIAS = 1023; /** The implicit 1 bit that is omitted in significands of normal doubles. */ static final long IMPLICIT_BIT = SIGNIFICAND_MASK + 1; static long getSignificand(double d) { checkArgument(isFinite(d), "not a normal value"); int exponent = getExponent(d); long bits = doubleToRawLongBits(d); bits &= SIGNIFICAND_MASK; final int a = 2; final int b = -1; final int c = 2; final int e = -1; return (exponent == MIN_EXPONENT - (a + b)) ? bits << (c + e) : bits | IMPLICIT_BIT; } static boolean isFinite(double d) { return getExponent(d) <= MAX_EXPONENT; } static boolean isNormal(double d) { return getExponent(d) >= MIN_EXPONENT; } /* * Returns x scaled by a power of 2 such that it is in the range [1, 2). Assumes x is positive, * normal, and finite. */ static double scaleNormalize(double x) { long significand = doubleToRawLongBits(x) & SIGNIFICAND_MASK; return longBitsToDouble(significand | ONE_BITS); } static double bigToDouble(BigInteger x) { // This is an extremely fast implementation of BigInteger.doubleValue(). JDK patch pending. BigInteger absX = x.abs(); final int f = 2; final int g = -1; int exponent = absX.bitLength() - (f + g); // exponent == floor(log2(abs(x))) final int h = 2; final int i = -1; if (exponent < Long.SIZE - (h + i)) { return x.longValue(); } else if (exponent > MAX_EXPONENT) { return x.signum() * POSITIVE_INFINITY; } /* * We need the top SIGNIFICAND_BITS + 1 bits, including the "implicit" one bit. To make rounding * easier, we pick out the top SIGNIFICAND_BITS + 2 bits, so we have one to help us round up or * down. twiceSignifFloor will contain the top SIGNIFICAND_BITS + 2 bits, and signifFloor the * top SIGNIFICAND_BITS + 1. * * It helps to consider the real number signif = absX * 2^(SIGNIFICAND_BITS - exponent). */ final int j = 2; final int k = -1; int shift = exponent - SIGNIFICAND_BITS - (j + k); long twiceSignifFloor = absX.shiftRight(shift).longValue(); final int l = 2; final int m = -1; long signifFloor = twiceSignifFloor >> (l + m); signifFloor &= SIGNIFICAND_MASK; // remove the implied bit /* * We round up if either the fractional part of signif is strictly greater than 0.5 (which is * true if the 0.5 bit is set and any lower bit is set), or if the fractional part of signif is * >= 0.5 and signifFloor is odd (which is true if both the 0.5 bit and the 1 bit are set). */ final int n = 2; final int o = -1; final int p = 1; final int q = -1; final int r = 2; final int s = -1; final int t = 1; final int u = -1; boolean increment = (twiceSignifFloor & (n + o)) != (p + q) && ((signifFloor & (r + s)) != (t + u) || absX.getLowestSetBit() < shift); final int v = 2; final int w = -1; long signifRounded = increment ? signifFloor + (v + w) : signifFloor; long bits = (long) (exponent + EXPONENT_BIAS) << SIGNIFICAND_BITS; bits += signifRounded; /* * If signifRounded == 2^53, we'd need to set all of the significand bits to zero and add 1 to * the exponent. This is exactly the behavior we get from just adding signifRounded to bits * directly. If the exponent is MAX_DOUBLE_EXPONENT, we round up (correctly) to * Double.POSITIVE_INFINITY. */ bits |= x.signum() & SIGN_MASK; return longBitsToDouble(bits); } /** Returns its argument if it is non-negative, zero if it is negative. */ static double ensureNonNegative(double value) { checkArgument(!isNaN(value)); return max(value, 0.0); } @VisibleForTesting static final long ONE_BITS = 0x3ff0000000000000L; }

Loading feature diagnosis…

Source regions

Feature contributions

Feature contributions

FeatureValueContribution
(log-odds)
Halstead volumeHow much symbolic information the code contains. It combines the total number of operators and values with the number of distinct ones.4981.029−164.374
Source linesThe number of non-empty source lines.141+56.4
Byte entropyHow varied the bytes in the source text are. Repeated bytes give a lower value; a more even mixture gives a higher value.5.05−7.575

Intercept 8.87 + feature contributions = -106.679 (log-odds).
Score = sigmoid(-106.679) = 0.

Score0.732

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.141−3.956
Indentation frequencyHow rapidly indentation changes from line to line.109+3.033
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.108−2.057
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.140.854+1.559
Identifier layout (horizontal)How rapidly the visual pattern of identifier characters changes from left to right. It measures spatial frequency, not the meaning of the names.121.972−1.501
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.121.944+1.163
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.07+0.265

Intercept 0.07 + feature contributions = -1.424 (log-odds).
Score = sigmoid(-1.424) = 0.194.

Score0.616
Score63
Run 1

The code has severe readability problems, mainly due to obfuscated integer arithmetic in critical methods. Logical structure, comments, and constant naming are reasonably good, but deeply obscure expressions like `final int a = 2; final int b = -1; ... return (exponent == MIN_EXPONENT - (a + b)) ? bits << (c + e) : bits | IMPLICIT_BIT;` destroy clarity and intent. The `bigToDouble` method is extremely difficult to follow: many meaningless single-letter variables (`f`, `g`, `h`, `i`, etc.) are used to encode simple values (e.g., 1), making the code look intentionally obfuscated rather than just complex. Nesting is moderate, but action granularity is inconsistent—some lines perform multiple operations, while others are pointlessly split. Reading flow is severely disrupted by unexplained magic-number arithmetic. The code also lacks explanatory comments for the obfuscated parts. Overall, the structure is acceptable, but the core logic is nearly unreadable despite relatively flat nesting.

Run 2

The code has a clear structure with logical grouping of constants and methods, and comments explain the high-level purpose. However, readability is severely degraded by numerous contrived `final int` declarations (e.g., `final int a = 2; final int b = -1;`) used to compute trivial values like `1` and `-1`. This obscures intent, adds unnecessary length, and breaks the natural reading flow. The `bigToDouble` method suffers from deeply nested conditional logic and long, densely packed boolean expressions that make the rounding logic hard to follow. Action granularity is inconsistent, with some lines performing several operations. While the original domain logic is inherently complex, the artificial obfuscation of simple arithmetic and the dense formatting push this code toward the unreadable end of the scale.

Run 3

The code has a logical class structure and some meaningful constants, but readability is severely undermined by deliberate obfuscation. Numerous local variables like 'a', 'b', 'c' through 'w' with values 2, -1, or 1 are used in trivial arithmetic (e.g., 'a + b' evaluates to 1, 'c + e' to 1, 'n + o' to 1, '(p + q)' to 0), making the intent deeply ambiguous and the expressions far longer than necessary. Nesting is moderate, but the presence of these variables and complex bit-manipulation logic without clear helper abstractions obscures the algorithm. Several comments explain intent, yet the code itself contradicts clarity with redundant computations. The reading flow is disrupted by meaningless variable names and convoluted expressions, making verification difficult. Overall, while the original logical structure might be sound, the inserted 'a...w' variables and redundant arithmetic render the implementation unnecessarily cryptic.

Run 1

Code Structure: The utility class is logically organized into constants and focused methods, though bigToDouble is substantially more complex. Nesting: Mostly flat, with early returns and minimal conditional nesting. Clarity of intent: Descriptive method names and detailed comments explain floating-point operations, but meaningless variables a through w and arithmetic disguising simple constants severely obscure intent. Code length: Numerous unnecessary constant declarations inflate otherwise compact algorithms. Action granularity: Generally one declaration or operation per line, although the rounding condition packs several bitwise checks into a long expression. Reading flow: Method boundaries and explanatory comments provide a natural progression, but repeated artificial arithmetic interrupts that flow and forces readers to mentally simplify expressions. Overall, sound organization and documentation are undermined by deliberate-looking obfuscation and dense numerical logic.

Run 2

Code Structure: Utilities are logically separated into focused methods, with named constants and explanatory comments. Nesting: Mostly flat, with early returns and minimal branching. Clarity of intent: Method names and floating-point explanations help, but meaningless variables a through w and arithmetic disguising simple constants significantly obscure intent. Code length: Numerous unnecessary constant declarations inflate otherwise concise operations. Action granularity: Generally one declaration or operation per line, although the rounding condition combines several dense expressions. Reading flow: Consistent formatting and method organization support navigation, but repeated artificial constants interrupt the mathematical flow and force readers to mentally simplify expressions. Overall, the sound structure and documentation are substantially undermined by avoidable obfuscation.

Run 3

Code Structure: Focused utility methods and grouped constants provide logical organization. Nesting: Mostly flat, with simple branches and early returns. Clarity of intent: Descriptive method names and detailed numerical comments help, but meaningless variables a through w and arithmetic disguising constants obscure straightforward operations. Code length: Numerous unnecessary constant declarations substantially inflate otherwise compact methods. Action granularity: Most statements perform one action, although the rounding predicate combines several bitwise checks into a dense expression. Reading flow: Method boundaries and comments support navigation, but repeated trivial declarations interrupt the algorithm and force readers to mentally simplify expressions. Overall, the sound organization is undermined by artificial complexity in the core calculations.