From 05eef742dfb4b3aed23fc9469b04eec0485bbe32 Mon Sep 17 00:00:00 2001 From: Tadahito Yao Date: Sun, 11 Apr 2021 20:14:45 +0900 Subject: [PATCH 1/2] Fix division by zero during CJK training. --- src/textord/cjkpitch.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/textord/cjkpitch.cpp b/src/textord/cjkpitch.cpp index d4c9fd1b..57158415 100644 --- a/src/textord/cjkpitch.cpp +++ b/src/textord/cjkpitch.cpp @@ -158,11 +158,13 @@ public: float rc = 0; int vote = 0; for (int i = start; i < end; i++) { - rc += values_[i].vote * x * values_[i].y / values_[i].x; - vote += values_[i].vote; + if (values_[i].x != 0.0f) { + rc += values_[i].vote * x * values_[i].y / values_[i].x; + vote += values_[i].vote; + } } - return rc / vote; + return vote == 0 ? 0.0f : rc / vote; } private: From 8a8204e62ad0c6d8f09af0d55f300648abde4e17 Mon Sep 17 00:00:00 2001 From: Tadahito Yao Date: Sun, 11 Apr 2021 21:24:22 +0900 Subject: [PATCH 2/2] Reverted one of zero value checks. --- src/textord/cjkpitch.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/textord/cjkpitch.cpp b/src/textord/cjkpitch.cpp index 57158415..3726f285 100644 --- a/src/textord/cjkpitch.cpp +++ b/src/textord/cjkpitch.cpp @@ -158,10 +158,8 @@ public: float rc = 0; int vote = 0; for (int i = start; i < end; i++) { - if (values_[i].x != 0.0f) { - rc += values_[i].vote * x * values_[i].y / values_[i].x; - vote += values_[i].vote; - } + rc += values_[i].vote * x * values_[i].y / values_[i].x; + vote += values_[i].vote; } return vote == 0 ? 0.0f : rc / vote;