Results for “Reporting & grouped calculations”
Small, practical examples. Search by task or narrow things down below.
Turn known group values into columns
SQL: Conditional aggregation gives a portable pivot when the category set is known.
SQL✓ Tested
Turn known group values into columns
SQL Server: Conditional aggregation gives a portable pivot when the category set is known.
SQL Server✓ Tested
Turn known group values into columns
Postgres: Conditional aggregation gives a portable pivot when the category set is known.
Postgres✓ Tested
Turn known group values into columns
SQLite: Conditional aggregation gives a portable pivot when the category set is known.
SQLite✓ Tested
Compare floating-point calculations with tolerance
Python: Use isclose instead of exact equality for results affected by floating-point rounding.
Python✓ Tested
Apply a linear sensor calibration
Arduino / C: Convert a raw reading using an offset and scale measured for the sensor.
Arduino / C✓ Tested
Calculate a two-dimensional vector length
C++: hypot avoids unnecessary intermediate overflow in the sum of squares.
C++✓ Tested
Calculate beyond the long integer range
Java: Use BigInteger when a fixed-width primitive type would overflow.
Java✓ Tested
Calculate the number of required pages
Python: Use integer arithmetic to round a nonnegative count up to a positive page size.
Python✓ Tested
Calculate with exact rational values
Python: Use Fraction for exact ratios rather than binary floating-point approximations.
Python✓ Tested
Check an upper integer bound before adding
C++: For these nonnegative values, compare against the maximum minus the addend first.
C++✓ Tested
Clamp a numeric value between bounds
Python: Combine min and max for a closed interval when lower is no greater than upper.
Python✓ Tested