A powerful and easy-to-use calculator application built with Jetpack Compose. This application supports both basic arithmetic and scientific calculations with a user-friendly interface.
Perform essential arithmetic operations with ease:
- ➕ Addition (+)
- ➖ Subtraction (-)
- ✖️ Multiplication (*)
- ➗ Division (/)
Unlock advanced mathematical operations:
- 📐 Trigonometric Functions:
sin(),cos(),tan() - 📊 Logarithmic Functions:
log(),ln() - 📈 Power and Root Calculations:
x^y,√x - 🎯 Factorial Calculation:
n!
- Enter numbers and select the arithmetic operation.
- Press the "=" button to view the result.
- Access advanced functions like trigonometry and logarithmic calculations.
- Perform complex operations seamlessly with intuitive input.
- Language: Kotlin
- Framework: Jetpack Compose
- Environment: Android Studio
MainActivity: Entry point of the application where theCalculatorUI()Composable is called.CalculatorUI(): Main calculator layout containing:- Display Box: Shows the user input and results.
- Button Grid: Includes all calculator buttons (numbers, operators, and scientific functions).
-
CalculatorButton(): A reusable Composable function to create buttons.- Parameters:
label: Button text (e.g., "+", "sin", "AC")onClick: Action performed on button click
- Parameters:
-
Button Categories:
- Basic Operations: "+", "-", "×", "÷"
- Scientific Operations:
sin,cos,tan,log,ln,√,!,%,^ - Special Functions:
AC(All Clear),⌫(Backspace),=(Evaluate)
newInput(): Validates and updates user input.- Ensures correct operator usage (e.g., prevents multiple decimals).
- Automatically multiplies constants like π or e when required.
- Handles bracket and other edge cases.
-
calculateResult(): Parses and evaluates mathematical expressions. -
evaluateExpression(): Core parsing logic to compute results.- Replaces custom symbols (×, ÷, π, e) with standard equivalents.
- Auto-closes open parentheses.
- Supports chained operations.
-
handleFunctions(): Processes trigonometric and logarithmic functions.- Supports both Radians and Degrees for
sin,cos, andtan.
- Supports both Radians and Degrees for
-
handleFactorial(): Calculates the factorial of a number. -
handlePower(): Evaluates exponentiation (e.g.,2^3). -
handleSquareRoot(): Computes square roots. -
handlePercentage(): Converts percentages to decimals.
-
findClosingParenthesis(): Finds the matching closing parenthesis for expressions. -
formatResult(): Formats the output, removing trailing zeros for clean display. -
degreesToRadians(): Converts degrees to radians for trigonometric calculations.
- Built-in error checks prevent invalid calculations (e.g., division by zero).
- Provides a
Errormessage for invalid inputs.
- Ensure you switch between Radians and Degrees using the Rad/Deg toggle.
- Factorials are supported only for positive integers.
- Invalid inputs return an
Errormessage.
Download and install the latest release from GitHub:
For any queries or feedback, reach out via:
- GitHub: DevanshuDubey

