mirror of
https://github.com/chylex/Query.git
synced 2025-07-06 00:04:39 +02:00
Compare commits
3 Commits
2b9d5bba8f
...
d52ec8a615
Author | SHA1 | Date | |
---|---|---|---|
d52ec8a615 | |||
5d640de7e5 | |||
d69c4672d6 |
@ -35,15 +35,29 @@ public abstract record Number : IAdditionOperators<Number, Number, Number>,
|
||||
|
||||
public override Number Pow(Number exponent) {
|
||||
if (exponent is Rational { Value: {} rationalExponent }) {
|
||||
Fraction fractionExponent = rationalExponent.GetImproperFraction();
|
||||
if (fractionExponent.Denominator == 1 && fractionExponent.Numerator >= 0) {
|
||||
Fraction fractionExponent = Fraction.ReduceToProperFraction(rationalExponent.GetImproperFraction());
|
||||
|
||||
if (fractionExponent.Numerator >= 0 && fractionExponent.Denominator == 1) {
|
||||
try {
|
||||
return new Rational(BigRational.Pow(Value, fractionExponent.Numerator));
|
||||
} catch (OverflowException) {}
|
||||
}
|
||||
|
||||
if (fractionExponent.Numerator == 1 && fractionExponent.Denominator > 1) {
|
||||
Number result = PowAsDecimal(exponent);
|
||||
|
||||
BigRational assumedPerfectPowerRoot = new BigRational(decimal.Floor(result.AsDecimal));
|
||||
BigRational assumedPerfectPower = BigRational.Pow(assumedPerfectPowerRoot, fractionExponent.Denominator);
|
||||
|
||||
return assumedPerfectPower == Value ? assumedPerfectPowerRoot : result;
|
||||
}
|
||||
}
|
||||
|
||||
return new Decimal(AsDecimal).Pow(exponent);
|
||||
return PowAsDecimal(exponent);
|
||||
|
||||
Number PowAsDecimal(Number number) {
|
||||
return new Decimal(AsDecimal).Pow(number);
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString(IFormatProvider? formatProvider) {
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<Authors>chylex</Authors>
|
||||
<Version>2.0.0.0</Version>
|
||||
<Version>2.1.0.0</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
|
Loading…
Reference in New Issue
Block a user