Skip to content

Commit 8d379fa

Browse files
Add power, root, log base, and hypot functions interface
1 parent e242377 commit 8d379fa

5 files changed

Lines changed: 52 additions & 4 deletions

File tree

src/GoogolSharp/Helpers/Float128PreciseTranscendentals.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ public static Float128 SafeExp(Float128 x)
448448
r * (Float128.Parse("0.0416666666666666666666666666666667", null) +
449449
r * (Float128.Parse("0.0083333333333333333333333333333333", null) +
450450
r * (Float128.Parse("0.0013888888888888888888888888888889", null) +
451-
r * (Float128.Parse("0.0001984126984126984126984126984127", null)))))));
451+
r * Float128.Parse("0.0001984126984126984126984126984127", null))))));
452452

453453
// Scale by 2^k to adjust for the reduction (k * ln(2) part)
454454
return Float128.ScaleB(poly, k);

src/GoogolSharp/Modules/IGoogologyFloat.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
* along with GoogolSharp. If not, see <https://www.gnu.org/licenses/>.
1717
*/
1818

19+
using System.Numerics;
20+
1921
namespace GoogolSharp
2022
{
2123
/// <summary>
@@ -48,7 +50,10 @@ public interface IGoogologyFloat<TSelf> :
4850
System.Numerics.IUnaryNegationOperators<TSelf, TSelf>,
4951
System.Numerics.IUnaryPlusOperators<TSelf, TSelf>,
5052
IUtf8SpanFormattable,
51-
IUtf8SpanParsable<TSelf>
53+
IUtf8SpanParsable<TSelf>,
54+
ILogarithmicFunctions<TSelf>,
55+
IPowerFunctions<TSelf>,
56+
IRootFunctions<TSelf>
5257
where TSelf : IGoogologyFloat<TSelf>
5358
{
5459
static abstract TSelf Neg(TSelf value);
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2025 @GreatCoder1000
3+
* This file is part of GoogolSharp.
4+
*
5+
* GoogolSharp is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* GoogolSharp is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with GoogolSharp. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
using GoogolSharp.Helpers;
20+
using QuadrupleLib;
21+
using QuadrupleLib.Accelerators;
22+
using Float128 = QuadrupleLib.Float128<QuadrupleLib.Accelerators.DefaultAccelerator>;
23+
24+
namespace GoogolSharp
25+
{
26+
partial struct Arithmonym
27+
{
28+
public static Arithmonym Log(Arithmonym inputV, Arithmonym baseV)
29+
{
30+
return inputV._Log10 / baseV._Log10;
31+
}
32+
33+
public static Arithmonym RootN(Arithmonym inputV, int rootV)
34+
{
35+
return (inputV._Log10 / rootV)._Exp10;
36+
}
37+
38+
public static Arithmonym Hypot(Arithmonym legA, Arithmonym legB)
39+
{
40+
return Sqrt(legA * legA + legB * legB);
41+
}
42+
}
43+
}

tests/GoogolSharp.Tests/Float128AcceptanceTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void DivisionBasic()
6767
public void NegationAndReciprocal()
6868
{
6969
var three = (Float128)3;
70-
AssertFloat128.Equal((Float128)(-3.0), (-three), 10);
70+
AssertFloat128.Equal((Float128)(-3.0), -three, 10);
7171
// reciprocal of three is one-third
7272
var recip = Float128.One / three;
7373
AssertFloat128.Equal((Float128)(1.0 / 3.0), recip, 10);

tests/GoogolSharp.Tests/Float128PreciseTranscendentalsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ private static int CountSignificantDigits(Float128 result, Float128 expected)
544544
// Otherwise, calculate how many digits are correct
545545
// digit_count ≈ -log10(relative_error)
546546
Float128 log10_error = Float128PreciseTranscendentals.SafeLog10(relative_error);
547-
int digits = (int)(-Float128.Floor(log10_error));
547+
int digits = (int)-Float128.Floor(log10_error);
548548

549549
return digits > 34 ? 34 : (digits < 0 ? 0 : digits);
550550
}

0 commit comments

Comments
 (0)