Skip to content

Add modulo, square root, and power of two operators to calculator - #18

Draft
haslam93 with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-16
Draft

Add modulo, square root, and power of two operators to calculator#18
haslam93 with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-16

Conversation

Copilot AI commented Jun 27, 2025

Copy link
Copy Markdown
Contributor

This PR implements three new mathematical operators for the calculator application as requested in the issue:

New Operators Added

1. Modulo Operator (%)

  • Operation: Returns the remainder of division (a % b)
  • API: GET /arithmetic?operation=modulo&operand1=X&operand2=Y
  • UI: % button and keyboard % key support
  • Example: 15 % 4 = 3

2. Square Root Operator (√)

  • Operation: Returns the square root of operand (√a)
  • API: GET /arithmetic?operation=sqrt&operand1=X
  • UI: button (unary operation - calculates immediately)
  • Example: √64 = 8

3. Power of Two Operator (x²)

  • Operation: Returns operand squared (a²)
  • API: GET /arithmetic?operation=power2&operand1=X
  • UI: button (unary operation - calculates immediately)
  • Example: 8² = 64

Implementation Details

Backend Changes (api/controller.js)

  • Added three new operations to the operations object
  • Modified validation logic to support unary operations that don't require operand2
  • Maintained backward compatibility with existing binary operations

Frontend Changes (public/client.js)

  • Extended switch statement to handle new operator symbols
  • Implemented unary operation logic that calculates immediately when operator is pressed
  • Added keyboard support for modulo operator (%)

UI Changes (public/index.html)

  • Added three new operator buttons to the calculator interface
  • Buttons are positioned after the existing operators for easy access

Comprehensive Testing (test/arithmetic.test.js)

  • Added 12 new unit tests (4 for each operator)
  • Tests cover edge cases including:
    • Positive and negative numbers
    • Zero values
    • Floating point numbers
    • Various mathematical scenarios

Quality Assurance

  • ✅ All 36 tests passing (24 existing + 12 new)
  • ✅ No regressions in existing functionality
  • ✅ ESLint clean with no warnings
  • ✅ Manual testing confirms UI functionality
  • ✅ API endpoints tested and verified

Acceptance Criteria Met

  • ✅ Pass unit tests for these operators
  • ✅ Operators visible in the UI of the calculator

The new operators are fully functional and integrate seamlessly with the existing calculator interface and API.

Fixes #16.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: haslam93 <36418598+haslam93@users.noreply.github.com>
Copilot AI changed the title [WIP] Add new operators Add modulo, square root, and power of two operators to calculator Jun 27, 2025
Copilot AI requested a review from haslam93 June 27, 2025 15:03
@haslam93

Copy link
Copy Markdown
Owner

clean up the UI

@haslam93

Copy link
Copy Markdown
Owner

@copilot Clean up the UI

Co-authored-by: haslam93 <36418598+haslam93@users.noreply.github.com>

Copilot AI commented Aug 18, 2025

Copy link
Copy Markdown
Contributor Author

@copilot Clean up the UI

UI has been cleaned up in commit 2eee1f4. Changes include:

  • Reorganized calculator buttons into a cleaner 4x6 grid layout
  • Removed TODO comments and empty button elements
  • Moved new operators (%, √, x²) to better positions in the layout
  • Made equals button span two columns for better visual balance
  • All functionality verified working correctly

Final cleaned UI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add new operators

2 participants