Skip to content

Commit f9fcdcd

Browse files
authored
Add support for .NET 8 Math functions (#3556)
1 parent db22eaa commit f9fcdcd

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

src/NHibernate/Linq/Functions/MathGenerator.cs

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,52 @@ public MathGenerator()
8080
ReflectHelper.FastGetMethod(MathF.Ceiling, default(float)),
8181

8282
ReflectHelper.FastGetMethod(MathF.Pow, default(float), default(float)),
83+
#endif
84+
#if NET8_0_OR_GREATER
85+
ReflectHelper.FastGetMethod(float.Sin, default(float)),
86+
ReflectHelper.FastGetMethod(float.Cos, default(float)),
87+
ReflectHelper.FastGetMethod(float.Tan, default(float)),
88+
ReflectHelper.FastGetMethod(float.Sinh, default(float)),
89+
ReflectHelper.FastGetMethod(float.Cosh, default(float)),
90+
ReflectHelper.FastGetMethod(float.Tanh, default(float)),
91+
ReflectHelper.FastGetMethod(float.Asin, default(float)),
92+
ReflectHelper.FastGetMethod(float.Acos, default(float)),
93+
ReflectHelper.FastGetMethod(float.Atan, default(float)),
94+
ReflectHelper.FastGetMethod(float.Atan2, default(float), default(float)),
95+
ReflectHelper.FastGetMethod(float.Sqrt, default(float)),
96+
ReflectHelper.FastGetMethod(float.Abs, default(float)),
97+
ReflectHelper.FastGetMethod(float.Sign, default(float)),
98+
ReflectHelper.FastGetMethod(float.Floor, default(float)),
99+
ReflectHelper.FastGetMethod(float.Ceiling, default(float)),
100+
ReflectHelper.FastGetMethod(float.Pow, default(float), default(float)),
101+
102+
ReflectHelper.FastGetMethod(double.Sin, default(double)),
103+
ReflectHelper.FastGetMethod(double.Cos, default(double)),
104+
ReflectHelper.FastGetMethod(double.Tan, default(double)),
105+
ReflectHelper.FastGetMethod(double.Sinh, default(double)),
106+
ReflectHelper.FastGetMethod(double.Cosh, default(double)),
107+
ReflectHelper.FastGetMethod(double.Tanh, default(double)),
108+
ReflectHelper.FastGetMethod(double.Asin, default(double)),
109+
ReflectHelper.FastGetMethod(double.Acos, default(double)),
110+
ReflectHelper.FastGetMethod(double.Atan, default(double)),
111+
ReflectHelper.FastGetMethod(double.Atan2, default(double), default(double)),
112+
ReflectHelper.FastGetMethod(double.Sqrt, default(double)),
113+
ReflectHelper.FastGetMethod(double.Abs, default(double)),
114+
ReflectHelper.FastGetMethod(double.Sign, default(double)),
115+
ReflectHelper.FastGetMethod(double.Floor, default(double)),
116+
ReflectHelper.FastGetMethod(double.Ceiling, default(double)),
117+
ReflectHelper.FastGetMethod(double.Pow, default(double), default(double)),
83118
#endif
84119
};
85120
}
86121

87122
public override HqlTreeNode BuildHql(MethodInfo method, Expression expression, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
88123
{
89-
string function = method.Name.ToLowerInvariant();
90-
91-
if (function == "pow")
92-
function = "power";
124+
var function = method.Name.ToLowerInvariant() switch
125+
{
126+
"pow" => "power",
127+
var f => f,
128+
};
93129

94130
var firstArgument = visitor.Visit(arguments[0]).AsExpression();
95131

src/NHibernate/Linq/Functions/RoundGenerator.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ public RoundGenerator()
2525
ReflectHelper.FastGetMethod(MathF.Round, default(float)),
2626
ReflectHelper.FastGetMethod(MathF.Round, default(float), default(int)),
2727
#endif
28+
29+
#if NET8_0_OR_GREATER
30+
ReflectHelper.FastGetMethod(float.Round, default(float)),
31+
ReflectHelper.FastGetMethod(float.Round, default(float), default(int)),
32+
ReflectHelper.FastGetMethod(double.Round, default(double)),
33+
ReflectHelper.FastGetMethod(double.Round, default(double), default(int)),
34+
#endif
2835
};
2936
}
3037

src/NHibernate/Linq/Functions/TruncateGenerator.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ public TruncateGenerator()
2020

2121
#if NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER
2222
ReflectHelper.FastGetMethod(MathF.Truncate, default(float)),
23+
#endif
24+
#if NET8_0_OR_GREATER
25+
ReflectHelper.FastGetMethod(float.Truncate, default(float)),
26+
ReflectHelper.FastGetMethod(double.Truncate, default(double)),
2327
#endif
2428
};
2529
}

0 commit comments

Comments
 (0)