Skip to content

Feature: Add decimals parameter to power #53

@ZCG-coder

Description

@ZCG-coder

Is your feature request related to a problem? Please describe.
Currently, the power method takes roots to find out the power, if the exponent is a decimal.

if (isDecimal(raiseTo))
{
// Raising to decimal power.
// Steps:
// 1. Convert the decimal to a fraction.
// 2. Raise the number to the numerator of the fraction.
// 3. Take the root of the number to the denominator of the fraction.
const auto& fraction = Fraction(raiseTo);
const auto& [top, bottom] = fraction.asArray();
const auto& powerResult = power(_number, top, 0);
const auto rootResult = root(powerResult, bottom, 8);
return reportPowerRoot(number, raiseTo, fraction, rootResult, steps);
}

However, on line 77...

const auto rootResult = root(powerResult, bottom, 8);

The root function is being called without specifying the number of decimals, so the default 8 decimal places is used. This causes a huge loss in precision.

Describe the solution you'd like

  • Add a parameter decimals to power.

Describe alternatives you've considered
None yet
Additional context
Add any other context or screenshots about the feature request here.

Metadata

Metadata

Assignees

Labels

C-C++Code - Pull requests that update C++ code.T-FeatureType - New feature or requestT-ImprovementType - Improvements to components.

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions