Skip to content

Add a power function to math.js #16

Mergedsyntaqx merged into mainrequested by syntaqx

Approved by g1t

ResolvedAdd a power function to math.js#15

Merged into main by syntaqx · f111277

g1tbotopened this pull request for syntaqx

I added power(base, exponent) to math.js, with a JSDoc block above it because the repository's house-style check requires one. It multiplies base by itself exponent times, so power(2, 10) gives 1024 and power(5, 0) gives 1. A negative exponent throws a RangeError.

I added a test in test.js for each of the three cases in the issue. node test.js passes locally. I did not run the CI workflows themselves, only the unit tests. I did not run the house-style script, but the JSDoc comment sits directly above function power, which is what it looks for.

I did not check that the exponent is a whole number. A fractional exponent such as 2.5 gives the result for 3 multiplications instead of throwing, because the issue only specified the negative case.

I put the function after multiply and changed only the module.exports line. PRs #14, #12 and #5 also edit math.js and test.js, so the exports line and the end of test.js may need a trivial merge resolution.

syntaqxmarked this ready for review·
g1tbotrequested a review from g1t·
g1tbotapproved these changes

Implementation is correct and complete. Verified:

  • power(2, 10) returns 1024 and power(5, 0) returns 1
  • power(2, -1) throws RangeError
  • Tests cover all three cases from the issue
  • Unit tests pass
  • House style check passes (JSDoc comment properly formatted)
  • No existing functionality broken

The implementation correctly handles whole-number exponents with appropriate error handling for negative values as specified in the requirements.

Reviewed by g1t on Claude Haiku 4.5.

syntaqxadded this to the merge queue·
syntaqxmerged this·

All checks have passed

7 passed · on f111277

Workflows

After build / workflow_run — After build passedDetails
Build / push — Build passedDetails
CI / push — CI passedDetails
Checks / merge_group — Checks passedDetails
Checks / pull_request — Checks passedDetails
Checks / push — Checks passedDetails
g1t / deploy — Production is live

Sign in to comment.