pCalc guide

The full reference. For an overview, see the README. A simple Android calculator, with your own formulas as first-class keys, a function plotter and history.

Written in Kotlin on the plain Android framework — no external libraries (no AndroidX, no Compose, no Material). The only dependency is the Kotlin standard library that the Kotlin Gradle plugin adds.

Features

Writing formulas

name(param1, param2, …) = expression
name = expression            # a named constant

Examples (these are pre-loaded on first run):

hyp(a, b)   = √(a^2 + b^2)
bmi(kg, m)  = kg ÷ m^2
vat         = 20
gross(net)  = net × (1 + vat%)
fib(n)      = if(n < 2, n, fib(n − 1) + fib(n − 2))

Formulas can use parameters, constants, ans, built-ins and other formulas, including recursion via the lazy if(cond, then, else). Names of built-ins are reserved. One-parameter formulas get a Plot button (name(x)).

Expression language

Operators+ − × ÷ ^ % (percent = ÷100), ! (factorial), √
Comparisons< > <= >= == != → 1 or 0 (= in an expression means ==)
Constantsπ / pi, e, ans (last result)
Functionssin cos tan asin acos atan sinh cosh tanh ln log(x[, base]) exp sqrt cbrt abs floor ceil round(x[, digits]) min max mod if
Conveniencesimplicit multiplication (2π, 3(x+1), 2sin(x)), auto-closing of (, scientific input 1.5E−7

Precedence, lowest to highest: comparisons → + − → × ÷ (and implicit) → unary − √ → ^ (right-associative, -2^2 = −4) → postfix % !.

Results are shown with up to 12 significant digits; very large/small values use E notation.

Project structure

app/src/main/java/x/vladgba/calc/
├── engine/               Pure Kotlin, no Android imports
│   ├── Lexer.kt          tokens (accepts both ASCII and × ÷ − √ π)
│   ├── Parser.kt         recursive-descent parser → AST
│   └── Calculator.kt     evaluator, built-ins, user formulas, formatting
├── CalcController.kt     keypad logic, cursor handling, persisted state
├── MainActivity.kt       calculator screen, pages, history panel
├── FormulasActivity.kt   formula list + editor dialog
├── GraphActivity.kt      graph screen (function list)
├── GraphView.kt          Canvas plotter (pan / zoom / trace)
├── PagerView.kt          minimal ViewPager replacement
├── PullDownLayout.kt     pull-down gesture for history
├── ExprField.kt          EditText that never shows the soft keyboard
├── MathStyle.kt          span styling for superscript powers
├── FormulaStore.kt / History.kt   SharedPreferences persistence (JSON)
└── Ui.kt                 small helpers (dp, ripples, system-bar insets)

The engine package has no Android dependencies and can be reused or unit-tested on the JVM.

Building

Requirements: JDK 17+, Android SDK with platform 35.

Open the project in IntelliJ IDEA / Android Studio and run the app configuration, or from the command line:

./gradlew assembleDebug          # app/build/outputs/apk/debug/app-debug.apk
./gradlew assembleRelease        # minified; signed with the debug key — set your own signingConfig

License

MIT © 2026 vladgba