diff --git a/src/char_model_trainer.cc b/src/char_model_trainer.cc index be0f0582..b758a8c0 100644 --- a/src/char_model_trainer.cc +++ b/src/char_model_trainer.cc @@ -37,7 +37,7 @@ util::Status Trainer::Train() { sum += it.second; } - const float logsum = log(sum); + const auto logsum = std::log(static_cast(sum)); CHECK_OR_RETURN(final_pieces_.empty()); for (const auto &it : Sorted(required_chars_)) { @@ -46,7 +46,7 @@ util::Status Trainer::Train() { break; } final_pieces_.emplace_back(string_util::UnicodeCharToUTF8(it.first), - log(it.second) - logsum); + std::log(static_cast(it.second)) - logsum); } if (trainer_spec_.use_all_vocab()) { diff --git a/src/unigram_model_trainer.cc b/src/unigram_model_trainer.cc index 86c75574..5f26771a 100644 --- a/src/unigram_model_trainer.cc +++ b/src/unigram_model_trainer.cc @@ -43,7 +43,7 @@ double Digamma(double x) { const double xx = 1.0 / x; const double xx2 = xx * xx; const double xx4 = xx2 * xx2; - result += log(x) + (1.0 / 24.0) * xx2 - (7.0 / 960.0) * xx4 + + result += std::log(x) + (1.0 / 24.0) * xx2 - (7.0 / 960.0) * xx4 + (31.0 / 8064.0) * xx4 * xx2 - (127.0 / 30720.0) * xx4 * xx4; return result; } diff --git a/src/word_model_trainer.cc b/src/word_model_trainer.cc index 8d759e40..ae274d98 100644 --- a/src/word_model_trainer.cc +++ b/src/word_model_trainer.cc @@ -47,7 +47,7 @@ util::Status Trainer::Train() { sum += it.second; } - const float logsum = log(sum); + const auto logsum = std::log(static_cast(sum)); CHECK_OR_RETURN(final_pieces_.empty()); for (const auto &it : Sorted(freq)) { @@ -58,7 +58,7 @@ util::Status Trainer::Train() { final_pieces_.size() == static_cast(vocab_size)) { break; } - final_pieces_.emplace_back(it.first, log(it.second) - logsum); + final_pieces_.emplace_back(it.first, std::log(static_cast(it.second)) - logsum); } if (trainer_spec_.use_all_vocab()) {