Sample

int-ddb0f8587130-I08

Select one of ten high-readability unrelated code templates per class

Matched original source

Lines126

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.7670–1; higher is more readable
Dorn0.3330–1; higher is more readable
Mi0.6170–1; higher is more readable
LLOC45Logical lines; fewer is more readable
DeepSeek V4 Pro12.670–20; mean of three runs
GPT-6.1 Sol15.330–20; mean of three runs
BTTF0.520–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) { { boolean featureEnabled = false; for (int toggleCount = 0; toggleCount < 3; toggleCount++) { featureEnabled = !featureEnabled; } } checkArgument(isFinite(d), "not a normal value"); int exponent = getExponent(d); long bits = doubleToRawLongBits(d); bits &= SIGNIFICAND_MASK; return (exponent == MIN_EXPONENT - 1) ? bits << 1 : 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(); int exponent = absX.bitLength() - 1; // exponent == floor(log2(abs(x))) if (exponent < Long.SIZE - 1) { 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). */ int shift = exponent - SIGNIFICAND_BITS - 1; long twiceSignifFloor = absX.shiftRight(shift).longValue(); long signifFloor = twiceSignifFloor >> 1; 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). */ boolean increment = (twiceSignifFloor & 1) != 0 && ((signifFloor & 1) != 0 || absX.getLowestSetBit() < shift); long signifRounded = increment ? signifFloor + 1 : 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.3758.09−124.017
Source linesThe number of non-empty source lines.126+50.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.118−7.677

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

Score0.767

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.126−3.425
Indentation frequencyHow rapidly indentation changes from line to line.94+2.514
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.93−1.713
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.125.851+1.349
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.94.528+0.721
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.99.945−0.568
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.06+0.359

Intercept 0.07 + feature contributions = -0.693 (log-odds).
Score = sigmoid(-0.693) = 0.333.

Score0.617
Score45
Run 1

The code is highly readable overall, with strong organization, clear intent, and appropriate granularity. Constants are well-named and documented, and methods are concise with explanatory comments where needed. The structure is logical, and nesting is minimal. However, there is a notable issue in `getSignificand`: a seemingly unrelated artificial block for a feature toggle, which breaks reading flow and clarity. Additionally, while `bigToDouble` is well-commented, it involves complex bit manipulation that may be hard to follow without deeper context. These minor issues slightly reduce readability.

Run 2

The code generally has clear purpose, good constants naming, and helpful comments explaining non-obvious bit manipulation, especially in bigToDouble. However, there are several readability issues. The getSignificand method contains an unrelated, dead-code loop toggling a local boolean, which is confusing and disrupts reading flow. The action granularity is inconsistent; some lines combine multiple operations while others are well-separated. There are also jarring inconsistencies such as misplaced or extra braces near getSignificand and a misplaced static field at the bottom of the file. These issues add clutter and make the structure feel tangled despite meaningful variable names and reasonable method length.

Run 3

The code demonstrates significant readability issues. The major problems include: a bizarre dead code block with an unnecessary loop inside getSignificand, inconsistent helper method availability (ONE_BITS is declared at the bottom but used above it), and unclear action granularity in several methods. The bigToDouble method has deeply complex bit manipulation with explanatory comments that are themselves hard to follow. While the class has a logical structure with clear section separation using comments for constants, and method names are mostly descriptive, the overall clarity is hampered by the dead code, scattered constant declarations, and complex nested logic. The reading flow is disrupted by having to jump between constant definitions and usage. Some methods like isFinite and isNormal are well-written and clear, but the complex bit-twiddling methods would benefit from extraction of helper methods. The presence of the nonsensical featureEnabled loop suggests poor code maintenance or generated code artifacts.

Run 1

Code Structure: Focused utility methods and named constants provide logical organization, but the unrelated featureEnabled block disrupts getSignificand. Nesting: Mostly flat, with early returns; the unnecessary block and loop add avoidable nesting. Clarity of intent: Descriptive names and detailed comments explain complex floating-point operations, though dense bitwise expressions require specialist knowledge and the toggle loop has no apparent purpose. Code length: Generally concise for the numerical complexity, with useful explanatory comments; the unused toggle logic is unnecessary. Action granularity: Statements typically perform one action per line, although rounding expressions combine several conditions. Reading flow: Methods follow clear computational sequences, but the poorly indented inserted block interrupts the flow, and ONE_BITS being declared at the end separates it from related constants.

Run 2

Code Structure: Cohesive utility methods and named constants provide logical organization, but the unrelated featureEnabled block disrupts getSignificand. Nesting: Mostly flat, with early returns; the unnecessary block and loop add avoidable nesting. Clarity of intent: Descriptive method names and detailed comments explain floating-point operations, although dense bit manipulation requires domain knowledge and the toggle loop has no apparent purpose. Code length: Generally justified by the numerical algorithm, but the unused toggle logic adds needless length. Action granularity: Statements generally perform one action per line; compound rounding expressions remain somewhat demanding. Reading flow: Methods follow a natural calculate-and-return progression, but inconsistent indentation in the inserted block, tightly packed imports, and ONE_BITS being declared at the end interrupt otherwise clear presentation.

Run 3

Code Structure: Well-separated utility methods and named constants provide logical organization, but the unrelated feature-toggle block disrupts getSignificand. Nesting: Mostly flat, with shallow conditionals; the redundant block and loop add unnecessary nesting. Clarity of intent: Descriptive names and detailed comments explain complex floating-point operations, although dense bitwise expressions require domain knowledge and the unused toggle has no apparent purpose. Code length: Generally appropriate for the algorithm, but the toggle block is unnecessary and some comments are lengthy. Action granularity: Statements generally perform one action per line, making intermediate calculations easy to follow. Reading flow: Methods progress naturally from validation through calculation to return, but inconsistent indentation in the inserted block and placement of ONE_BITS at the end slightly interrupt the flow.