OSDN Git Service

[Refactor] mysqrt() を削除し、std::sqrt に差し替えた
authorHourier <66951241+Hourier@users.noreply.github.com>
Mon, 1 May 2023 13:07:11 +0000 (22:07 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Mon, 1 May 2023 13:07:11 +0000 (22:07 +0900)
src/monster/monster-list.cpp
src/term/z-util.cpp
src/term/z-util.h

index d3a3a44..734868d 100644 (file)
@@ -45,6 +45,7 @@
 #include "util/probability-table.h"
 #include "view/display-messages.h"
 #include "world/world.h"
+#include <cmath>
 #include <iterator>
 
 #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<int>(std::sqrt(max_level * 10000)) + (max_level * 5);
     if (!max_level) {
         delay = 360;
     }
index 88f8e16..a483632 100644 (file)
@@ -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;
-}
index 54a2aed..81fa0e3 100644 (file)
@@ -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);