A scientific calculator implemented in C with GTK4 GUI. Originally intended as a clone of Google's calculator but evolved into a more comprehensive scientific calculator application.
-
Scientific Functions:
- Basic arithmetic operations (+, −, ×, ÷)
- Trigonometric functions (sin, cos, tan) with DEG/RAD mode toggle
- Inverse trigonometric functions (sin⁻¹, cos⁻¹, tan⁻¹)
- Logarithmic functions (ln, log)
- Exponential functions (e^x)
- Square root (√), power (x^y), and factorial (!)
- Constants (π, e)
- Parentheses for complex expressions
- Reciprocal (1/x) and negation (+/−)
-
Calculator Functions:
- Decimal point support
- Percentage calculations
- Clear (C) and backspace (←) functionality
- Proper operator precedence and chaining
-
GUI Features:
- GTK4-based interface with responsive grid layout
- Clean, functional design with color-coded buttons
- Large monospace display for clear number visibility
- Support for both keyboard input and button clicks
- GTK 4.0 or later
- GLib 2.0
- Cairo graphics library
- Pango text rendering
- Graphene geometry library
- GCC compiler
- Math library (libm)
cd src
make./calculatorOr use the convenience target:
make runThe project includes unit tests:
make testcalculator.c- Main GUI application and event handlerscalculator_logic.c- Core calculator computation logiccalculator_logic.h- Calculator logic header and data structuresMakefile- Build configuration with GTK4 and math library supporttest_calculator.c- Unit tests for calculator logic
- Click number buttons to enter values
- Click operator buttons (+, −, ×, ÷) to perform operations
- Use scientific function buttons (sin, cos, tan, etc.) for advanced calculations
- Press = to calculate the result
- Use ← to delete the last digit
- Use C to clear everything
- Toggle between DEG and RAD modes using the DEG/RAD button
- Use parentheses to group operations
The calculator uses a stack-based expression evaluator that handles operator precedence correctly. The GUI is separated from the calculation logic, following a clean architectural pattern.
This project is licensed under the MIT License.
Feel free to submit issues or pull requests to improve the calculator functionality or user interface.