From 60076c08560c414bf1438cb5e89ea02f5690aab2 Mon Sep 17 00:00:00 2001 From: Hourier <66951241+Hourier@users.noreply.github.com> Date: Mon, 1 May 2023 22:07:11 +0900 Subject: [PATCH] =?utf8?q?[Refactor]=20mysqrt()=20=E3=82=92=E5=89=8A?= =?utf8?q?=E9=99=A4=E3=81=97=E3=80=81std::sqrt=20=E3=81=AB=E5=B7=AE?= =?utf8?q?=E3=81=97=E6=9B=BF=E3=81=88=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/monster/monster-list.cpp | 3 ++- src/term/z-util.cpp | 39 --------------------------------------- src/term/z-util.h | 1 - 3 files changed, 2 insertions(+), 41 deletions(-) diff --git a/src/monster/monster-list.cpp b/src/monster/monster-list.cpp index d3a3a442c..734868d6d 100644 --- a/src/monster/monster-list.cpp +++ b/src/monster/monster-list.cpp @@ -45,6 +45,7 @@ #include "util/probability-table.h" #include "view/display-messages.h" #include "world/world.h" +#include #include #define HORDE_NOGOOD 0x01 /*!< (未実装フラグ)HORDE生成でGOODなモンスターの生成を禁止する? */ @@ -94,7 +95,7 @@ MONSTER_IDX m_pop(FloorType *floor_ptr) MonsterRaceId get_mon_num(PlayerType *player_ptr, DEPTH min_level, DEPTH max_level, BIT_FLAGS option) { /* town max_level : same delay as 10F, no nasty mons till day18 */ - auto delay = mysqrt(max_level * 10000L) + (max_level * 5); + auto delay = static_cast(std::sqrt(max_level * 10000)) + (max_level * 5); if (!max_level) { delay = 360; } diff --git a/src/term/z-util.cpp b/src/term/z-util.cpp index 88f8e161c..a48363221 100644 --- a/src/term/z-util.cpp +++ b/src/term/z-util.cpp @@ -303,42 +303,3 @@ int count_bits(BIT_FLAGS x) return n; } - -/*! - * @brief 平方根を切り捨て整数で返す - * @param n 数値 - * @return 平方根 - */ -int mysqrt(int n) -{ - int tmp = n >> 1; - int tasu = 10; - int kaeriti = 1; - - if (!tmp) { - if (n) { - return 1; - } else { - return 0; - } - } - - while (tmp) { - if ((n / tmp) < tmp) { - tmp >>= 1; - } else { - break; - } - } - kaeriti = tmp; - while (tasu) { - if ((n / tmp) < tmp) { - tasu--; - tmp = kaeriti; - } else { - kaeriti = tmp; - tmp += tasu; - } - } - return kaeriti; -} diff --git a/src/term/z-util.h b/src/term/z-util.h index 54a2aedf3..81fa0e380 100644 --- a/src/term/z-util.h +++ b/src/term/z-util.h @@ -73,4 +73,3 @@ void s64b_div(int32_t *A1, uint32_t *A2, int32_t B1, uint32_t B2); void s64b_mod(int32_t *A1, uint32_t *A2, int32_t B1, uint32_t B2); int count_bits(BIT_FLAGS x); -int mysqrt(int n); -- 2.11.0