VS Code Extensions
Inline Expression Calc

Inline Expression Calc

by srejv

A VS Code extension for evaluating and replacing numeric expressions inline, with C/C++ support for integers, floating-point values, bitwise operators, and literal formatting.

Downloads

11

Rating

— (0)

Version

0.0.1

Last updated

Apr 09, 2026

Evaluate numeric expressions directly inside your code and replace them with the result.

Inline Expression Calc is designed for source code, especially C and C++, where values like array sizes, masks, shifts, and floating point constants often need to be simplified in place.

Features

  • Calculates expressions under the cursor and replaces them inline
  • Works from the command palette, editor context menu, lightbulb refactor action, and a default keybinding
  • C/C++-friendly expression detection for () and []
  • Supports integer, float, and double literals
  • Supports decimal, binary, octal, hexadecimal, and hexadecimal floating point literals
  • Preserves or normalizes floating point formatting through settings
  • Optionally preserves integer literal style such as 0x, 0b, octal, and suffixes

Examples

int buffer[129 + 33];

becomes:

int buffer[162];
float scale = (1.25f + 2.5f);

becomes:

float scale = (3.75f);
auto mask = 0x10u + 0x2u;

with mathCalc.resultLiteralStyle set to preserve, becomes:

auto mask = 0x12u;

How It Works

Place the cursor inside a numeric expression and run Inline Expression Calc: Calculate Expression.

The extension prefers the innermost expression surrounded by () or []. If there is no enclosing pair, it falls back to a loose arithmetic expression on the current line.

Commands

  • Inline Expression Calc: Calculate Expression

Default keybinding:

  • Windows/Linux: Ctrl+Alt+M
  • macOS: Cmd+Alt+M

Settings

  • mathCalc.floatingPointFormat Controls how floating point results are written back. preserve keeps whole-valued floating point results as 3.0 or 3.0f. scientific always uses exponential notation. trim rounds to the configured precision and removes trailing floating point noise.

  • mathCalc.floatingPointPrecision Significant digits used by scientific and trim formatting modes.

  • mathCalc.resultLiteralStyle Controls whether integer results are always written in decimal or try to preserve source literal style where practical.

Supported Syntax

  • Decimal integers and floating point literals
  • Binary literals such as 0b1000
  • Hexadecimal literals such as 0x20
  • C-style octal literals such as 010
  • Integer suffixes such as u, ul, and ll
  • Decimal exponent notation such as 1e-3
  • Hexadecimal floating point literals such as 0x1.8p1
  • C++ digit separators using '
  • Nested parentheses

Supported operators:

  • Integer: +, -, *, /, %, <<, >>, &, |, ^, ~
  • Floating point: +, -, *, /

Safety and Scope

This extension is intentionally conservative:

  • It avoids loose-expression calculation inside C++ template argument lists
  • It avoids loose-expression calculation on C/C++ preprocessor lines
  • It does not attempt to resolve identifiers, macros, constants, or symbols
  • It currently evaluates expressions on the current line only

Best Fit

Inline Expression Calc is most useful when simplifying:

  • array sizes
  • bit masks
  • shift expressions
  • numeric literals in C or C++ source
  • hand-written floating point constants

Development

npm install
npm test

Press F5 to launch an Extension Development Host.