Skip to content

Improve nthRoot handling for negative inputs#72

Merged
pavanvamsi3 merged 1 commit intomasterfrom
codex/improve-newton_raphson.js-function
Jun 8, 2025
Merged

Improve nthRoot handling for negative inputs#72
pavanvamsi3 merged 1 commit intomasterfrom
codex/improve-newton_raphson.js-function

Conversation

@pavanvamsi3
Copy link
Collaborator

Summary

  • validate parameters for nthRoot
  • return early on zero values
  • handle odd roots of negative numbers by accounting for sign

Testing

  • npm test

https://chatgpt.com/codex/tasks/task_e_6844c3af04848333a6fe477d719df018

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves the nthRoot function to handle negative inputs and validates parameters while preserving existing behavior. Key changes include:

  • Adding basic parameter validation for n.
  • Returning early for zero inputs.
  • Handling odd roots of negative numbers by accounting for the sign and applying an iterative Newton–Raphson approach for other cases.


return result.toPrecision(6);
result *= sign;
return Number(result.toPrecision(6)).toString();
Copy link

Copilot AI Jun 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider simplifying the conversion chain by either directly returning result.toPrecision(6) for consistency with the earlier branches or clearly documenting the need for converting to a Number then back to a String.

Suggested change
return Number(result.toPrecision(6)).toString();
return result.toPrecision(6);

Copilot uses AI. Check for mistakes.
@pavanvamsi3 pavanvamsi3 merged commit 236d38d into master Jun 8, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants