https://github.com/seehiong/swift-calc
https://github.com/seehiong/swift-calc
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/seehiong/swift-calc
- Owner: seehiong
- License: mit
- Created: 2025-07-27T11:27:31.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2025-07-27T13:21:28.000Z (2 months ago)
- Last Synced: 2025-07-27T13:22:30.181Z (2 months ago)
- Language: TypeScript
- Size: 288 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SwiftCalc
A comprehensive, professional-grade calculator suite built with React, TypeScript, and Tailwind CSS. SwiftCalc provides multiple calculator modes including Standard, Scientific, Graphing, Financial, and Unit Conversion calculators - all in one swift, elegant interface.

## โจ Features
### ๐งฎ Calculator Modes
- **Standard Calculator**: Basic arithmetic operations with memory functions
- **Scientific Calculator**: Advanced mathematical functions, trigonometry, logarithms, and more
- **Graphing Calculator**: Plot mathematical functions with customizable viewing windows
- **Financial Calculator**: Loan payments, compound interest, and investment calculations
- **Unit Converter**: Convert between various units (length, weight, temperature, area, volume, time)### ๐จ User Experience
- **Dark/Light Mode**: Toggle between themes for comfortable viewing
- **Calculation History**: Track and reuse previous calculations
- **Responsive Design**: Works seamlessly on desktop, tablet, and mobile devices
- **Professional UI**: Clean, modern interface with smooth animations
- **Memory Functions**: Store and recall values across calculations### ๐ง Technical Features
- **Real-time Graphing**: Interactive function plotting with Chart.js
- **Mathematical Expression Parsing**: Powered by Math.js for accurate calculations
- **Type Safety**: Full TypeScript implementation
- **Performance Optimized**: Efficient rendering and state management
- **Accessibility**: Keyboard navigation and screen reader support## ๐ Getting Started
### Prerequisites
- Node.js (version 16 or higher)
- npm or yarn package manager### Installation
1. **Clone the repository**
```bash
git clone https://github.com/seehiong/swift-calc.git
cd swift-calc
```2. **Install dependencies**
```bash
npm install
```3. **Start the development server**
```bash
npm run dev
```4. **Open your browser**
Navigate to `http://localhost:5173` to view the application.### Building for Production
```bash
# Build the application
npm run build# Preview the production build
npm run preview
```## ๐ฑ Usage Guide
### Standard Calculator
- Basic arithmetic operations (+, -, ร, รท)
- Memory functions (MC, MR, M+, M-)
- Percentage calculations
- Sign toggle and decimal operations### Scientific Calculator
- Trigonometric functions (sin, cos, tan) with degree/radian modes
- Logarithmic functions (log, ln)
- Power and root operations
- Constants (ฯ, e)
- Factorial and inverse functions### Graphing Calculator
- Plot multiple functions simultaneously
- Customizable viewing window (X/Y min/max)
- Function visibility toggle
- Color-coded function lines
- Interactive zoom and pan### Financial Calculator
- **Loan Calculator**: Calculate monthly payments, total interest
- **Compound Interest**: Calculate growth with various compounding frequencies
- **Investment Calculator**: Plan future value with regular contributions### Unit Converter
- **Length**: Meters, kilometers, inches, feet, miles, etc.
- **Weight**: Kilograms, pounds, ounces, stones, etc.
- **Temperature**: Celsius, Fahrenheit, Kelvin
- **Area**: Square meters, acres, hectares, etc.
- **Volume**: Liters, gallons, cups, fluid ounces, etc.
- **Time**: Seconds, minutes, hours, days, years, etc.## ๐ ๏ธ Technology Stack
- **Frontend Framework**: React 18
- **Language**: TypeScript
- **Styling**: Tailwind CSS
- **Mathematical Engine**: Math.js
- **Charting**: Chart.js with React-Chart.js-2
- **Icons**: Lucide React
- **Build Tool**: Vite
- **Linting**: ESLint with TypeScript support## ๐ Project Structure
```
src/
โโโ components/
โ โโโ calculators/
โ โ โโโ StandardCalculator.tsx
โ โ โโโ ScientificCalculator.tsx
โ โ โโโ GraphingCalculator.tsx
โ โ โโโ FinancialCalculator.tsx
โ โ โโโ ConversionCalculator.tsx
โ โโโ BoltBadge.tsx
โ โโโ CalculatorButton.tsx
โ โโโ Display.tsx
โ โโโ History.tsx
โ โโโ ModeSelector.tsx
โโโ hooks/
โ โโโ useCalculator.ts
โโโ types/
โ โโโ calculator.ts
โโโ App.tsx
โโโ main.tsx
```## ๐งฎ **Complete Scientific Calculator Button Test Cases**
### **Row 1 - Trigonometric & Logarithmic Functions**
| Button | Test Input | Expected Result | Expression Shown |
|--------|------------|-----------------|------------------|
| **sin** | `30` โ `sin` โ `=` | `0.5` (DEG mode) | `sin(30)` |
| **sinโปยน** | `INV` โ `0.5` โ `sin` โ `=` | `30` (DEG mode) | `asin(0.5)` |
| **cos** | `60` โ `cos` โ `=` | `0.5` (DEG mode) | `cos(60)` |
| **cosโปยน** | `INV` โ `0.5` โ `cos` โ `=` | `60` (DEG mode) | `acos(0.5)` |
| **tan** | `45` โ `tan` โ `=` | `1` (DEG mode) | `tan(45)` |
| **tanโปยน** | `INV` โ `1` โ `tan` โ `=` | `45` (DEG mode) | `atan(1)` |
| **log** | `100` โ `log` โ `=` | `2` | `log10(100)` |
| **10หฃ** | `INV` โ `2` โ `log` โ `=` | `100` | `10^(2)` |
| **ln** | `e` โ `ln` โ `=` | `1` | `log(e)` |
| **eหฃ** | `INV` โ `1` โ `ln` โ `=` | `2.71828...` | `exp(1)` |
| **x!** | `5` โ `x!` โ `=` | `120` | `5!` |### **Row 2 - Constants & Powers**
| Button | Test Input | Expected Result | Expression Shown |
|--------|------------|-----------------|------------------|
| **ฯ** | `ฯ` โ `=` | `3.14159265359` | `pi` |
| **e** | `e` โ `=` | `2.71828182846` | `e` |
| **xยฒ** | `5` โ `xยฒ` | `25` (immediate) | - |
| **โx** | `9` โ `โx` | `3` (immediate) | - |
| **xสธ** | `2` โ `xสธ` โ `3` โ `=` | `8` | `2^3` |
| **(** | `5` โ `(` โ `2` โ `+` โ `3` โ `)` โ `=` | `25` | `5(2 + 3)` |### **Row 3 - Clear & Basic Operations**
| Button | Test Input | Expected Result | Notes |
|--------|------------|-----------------|-------|
| **AC** | Any calculation โ `AC` | `0`, clears all | Resets everything |
| **C** | `123` โ `C` | `0` | Clears display only |
| **)** | `(` โ `2` โ `+` โ `3` โ `)` | Shows in expression | Closes parentheses |
| **รท** | `10` โ `รท` โ `2` โ `=` | `5` | `10 / 2` |
| **ร** | `6` โ `ร` โ `7` โ `=` | `42` | `6 * 7` |
| **DEL** | `123` โ `DEL` | `12` | Removes last digit |### **Row 4 - Numbers & Operations**
| Button | Test Input | Expected Result | Expression Shown |
|--------|------------|-----------------|------------------|
| **7,8,9** | `789` | `789` | Number input |
| **โ** | `10` โ `โ` โ `3` โ `=` | `7` | `10 - 3` |
| **%** | `50` โ `%` | `0.5` (immediate) | Converts to decimal |
| **1/x** | `4` โ `1/x` | `0.25` (immediate) | Reciprocal |### **Row 5 - Numbers & Operations**
| Button | Test Input | Expected Result | Expression Shown |
|--------|------------|-----------------|------------------|
| **4,5,6** | `456` | `456` | Number input |
| **+** | `5` โ `+` โ `3` โ `=` | `8` | `5 + 3` |
| **ยฑ** | `5` โ `ยฑ` | `-5` (immediate) | Sign toggle |
| **EXP** | `1.5` โ `EXP` โ `10` | `1.5e10` | Scientific notation |### **Row 6 - Numbers & Special Functions**
| Button | Test Input | Expected Result | Expression Shown |
|--------|------------|-----------------|------------------|
| **1,2,3** | `123` | `123` | Number input |
| **=** | Any expression โ `=` | Calculated result | Executes calculation |
| **Ans** | Previous result โ `Ans` | Last answer | Recalls last result |
| **mod** | `10` โ `mod` โ `3` โ `=` | `1` | `10 mod 3` |### **Row 7 - Zero, Decimal & Advanced**
| Button | Test Input | Expected Result | Expression Shown |
|--------|------------|-----------------|------------------|
| **Rand** | `Rand` | `0.xxxxx` | Random number 0-1 |
| **0** | `0` or `120` | `0` or `1200` | Number input (spans 2 cols) |
| **.** | `5` โ `.` โ `25` | `5.25` | Decimal point |
| **\|x\|** | `-5` โ `\|x\|` | `5` (immediate) | Absolute value |### **Mode Toggles**
| Button | Test | Expected Result |
|--------|------|-----------------|
| **DEG/RAD** | `ฯ` โ `sin` โ `=` | DEG: `0`, RAD: `0` |
| **INV** | Toggle โ functions change | sinโsinโปยน, etc. |## ๐งช **Complex Test Cases**
1. **Nested Functions**: `cos(sin(45))` โ DEG mode โ `0.99992384661`
2. **Mixed Operations**: `2^3 + sqrt(16) - log(100)` โ `8 + 4 - 2 = 10`
3. **Parentheses**: `(2 + 3) * (4 - 1)` โ `5 * 3 = 15`
4. **Constants**: `ฯ * e^2` โ `โ22.87`
5. **Pi with Functions**: `sin(cos(ฯ))` โ DEG mode โ `0.017426180743`
6. **Scientific Notation**: `1.5e3 + 500` โ `2000`### **Additional Complex Function Tests**
| Input Sequence | Expected Result | Notes |
|----------------|-----------------|-------|
| `45` โ `sin` โ `cos` โ `=` | `0.99992384661` | cos(sin(45ยฐ)) in DEG mode |
| `45` โ `cos` โ `sin` โ `=` | `0.012341028215` | sin(cos(45ยฐ)) in DEG mode |
| `ฯ` โ `cos` โ `sin` โ `=` | `0.017426180743` | sin(cos(ฯยฐ)) in DEG mode |
| `30` โ `cos` โ `sin` โ `tan` โ `=` | `0.0002637963853` | tan(sin(cos(30ยฐ))) in DEG mode |
| `ฯ` โ `sin` โ `cos` โ `=` | TBD | cos(sin(ฯยฐ)) in DEG mode |## ๐ฏ Key Components
### Calculator Hook (`useCalculator.ts`)
Central state management for all calculator operations, including:
- Display state management
- Memory operations
- Calculation history
- Mode switching
- Theme toggling### Calculator Components
Each calculator mode is implemented as a separate component with specialized functionality:
- Modular design for easy maintenance
- Consistent UI patterns across modes
- Optimized performance for complex calculations## ๐ง Available Scripts
- `npm run dev` - Start development server
- `npm run build` - Build for production
- `npm run preview` - Preview production build
- `npm run lint` - Run ESLint## ๐ Features in Detail
### Memory Functions
- **MC (Memory Clear)**: Clear stored memory
- **MR (Memory Recall)**: Recall stored value
- **M+ (Memory Add)**: Add current display to memory
- **M- (Memory Subtract)**: Subtract current display from memory### Scientific Functions
- Trigonometric: sin, cos, tan (with inverse functions)
- Logarithmic: log (base 10), ln (natural log)
- Power operations: xยฒ, x^y, โx
- Constants: ฯ (pi), e (Euler's number)
- Special functions: factorial (!), absolute value### Graph Features
- Multiple function plotting
- Real-time function updates
- Customizable axis ranges
- Function visibility controls
- Color-coded function identification## ๐ค Contributing
1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request## ๐ License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## ๐ Acknowledgments
- Developed by [seehiong](https://github.com/seehiong)
- Built with [Bolt.new](https://bolt.new/) - AI-powered development platform
- Mathematical calculations powered by [Math.js](https://mathjs.org/)
- Charts rendered with [Chart.js](https://www.chartjs.org/)
- Icons provided by [Lucide React](https://lucide.dev/)
- Styling with [Tailwind CSS](https://tailwindcss.com/)## ๐ Support
If you encounter any issues or have questions, please:
1. Check the existing [issues on GitHub](https://github.com/seehiong/swift-calc/issues)
2. Create a [new issue](https://github.com/seehiong/swift-calc/issues/new) with detailed information
3. Include steps to reproduce any bugs---