From cfbab07631225ca025ec9f2a3f8982b13b6a76a3 Mon Sep 17 00:00:00 2001 From: Sergei Trofimovich Date: Sun, 5 Nov 2017 22:54:28 +0000 Subject: [PATCH] nsSBCSGroupProber.cpp: accound to FPU imprecision For (pseudo-)code like max([1.01, 1.01, 1.01]) real FPU hardware does not guarantee stable output. For example on 387 FPU internal precision is 80 bits thus loading/storing from 80-bit register into 32-bit memory slot slightly changes value of computation: https://gcc.gnu.org/wiki/x87note (note other hardware can deviate from IEEE-754 either by construction or being in certain modes) This change accounts for minor value deviation by picking not necessarily biggest vaue but the one that is far enough from previous value (> FLT_EPSILON). Signed-off-by: Sergei Trofimovich --- src/nsSBCSGroupProber.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/nsSBCSGroupProber.cpp b/src/nsSBCSGroupProber.cpp index f956d25..c2dd33f 100644 --- a/src/nsSBCSGroupProber.cpp +++ b/src/nsSBCSGroupProber.cpp @@ -36,6 +36,7 @@ * * ***** END LICENSE BLOCK ***** */ +#include #include #include "prmem.h" @@ -301,7 +302,11 @@ float nsSBCSGroupProber::GetConfidence(void) if (!mIsActive[i]) continue; cf = mProbers[i]->GetConfidence(); - if (bestConf < cf) + // make sure the difference is more fhan FPU noise + // to make max() stable. See the discusstion at: + // https://bugs.freedesktop.org/show_bug.cgi?id=101033 + // https://github.com/gentoo/gentoo/pull/5993#issuecomment-338335710 + if (cf - bestConf > FLT_EPSILON) { bestConf = cf; mBestGuess = i; -- 2.15.0