Skip to content

Commit

Permalink
BUG: Lucene.Net.Expressions.ScoreFunctionValues::DoubleVal(): Assigni…
Browse files Browse the repository at this point in the history
…ng float to double loses precision in x86 .NET Framework. Do an intermediate cast to decimal to fix Lucene.Net.Expressions.TestExpressionSorts::TestQueries(). See #269.
  • Loading branch information
NightOwl888 committed Oct 23, 2021
1 parent cb4bc0c commit bfa4c68
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/Lucene.Net.Expressions/ScoreFunctionValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ public override double DoubleVal(int document)
try
{
if (Debugging.AssertsEnabled) Debugging.Assert(document == scorer.DocID);

#if NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER
return scorer.GetScore();
#else
// LUCENENET specific: The intermediate cast to decimal is required here to prevent us from losing precision on x86 .NET Framework with optimizations enabled
return (double)(decimal)scorer.GetScore();
#endif
}
catch (Exception exception) when (exception.IsIOException())
{
Expand Down
3 changes: 0 additions & 3 deletions src/Lucene.Net.Tests.Expressions/TestExpressionSorts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ public override void TearDown()
}

[Test]
#if NETFRAMEWORK
[AwaitsFix(BugUrl = "https://github.com/apache/lucenenet/issues/269")] // LUCENENET TODO: this test fails on x86 on .NET Framework in Release mode only
#endif
public virtual void TestQueries()
{
int n = AtLeast(4);
Expand Down

0 comments on commit bfa4c68

Please sign in to comment.