An open API service indexing awesome lists of open source software.

https://github.com/seehiong/swift-calc


https://github.com/seehiong/swift-calc

Last synced: about 2 months ago
JSON representation

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.

![Calculator Suite](https://images.pexels.com/photos/6238297/pexels-photo-6238297.jpeg?auto=compress&cs=tinysrgb&w=1200&h=400&fit=crop)

## โœจ 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

---