-/* File: z-util.c */
+/* File: z-util.c */
/*
* Copyright (c) 1997 Ben Harrison
/*
* Convenient storage of the program name
*/
-cptr argv0 = NULL;
+concptr argv0 = NULL;
/*
* Determine if string "t" is equal to string "t"
*/
-bool streq(cptr a, cptr b)
+bool streq(concptr a, concptr b)
{
return (!strcmp(a, b));
}
/*
* Determine if string "t" is a suffix of string "s"
*/
-bool suffix(cptr s, cptr t)
+bool suffix(concptr s, concptr t)
{
int tlen = strlen(t);
int slen = strlen(s);
/*
* Determine if string "t" is a prefix of string "s"
*/
-bool prefix(cptr s, cptr t)
+bool prefix(concptr s, concptr t)
{
/* Scan "t" */
while (*t)
/*
* Redefinable "plog" action
*/
-void (*plog_aux)(cptr) = NULL;
+void (*plog_aux)(concptr) = NULL;
/*
* Print (or log) a "warning" message (ala "perror()")
* Note the use of the (optional) "plog_aux" hook.
*/
-void plog(cptr str)
+void plog(concptr str)
{
/* Use the "alternative" function if possible */
if (plog_aux) (*plog_aux)(str);
/*
* Redefinable "quit" action
*/
-void (*quit_aux)(cptr) = NULL;
+void (*quit_aux)(concptr) = NULL;
/*
* Exit (ala "exit()"). If 'str' is NULL, do "exit(0)".
* Otherwise, plog() 'str' and exit with an error code of -1.
* But always use 'quit_aux', if set, before anything else.
*/
-void quit(cptr str)
+void quit(concptr str)
{
/* Attempt to use the aux function */
if (quit_aux) (*quit_aux)(str);
/*
* Redefinable "core" action
*/
-void (*core_aux)(cptr) = NULL;
+void (*core_aux)(concptr) = NULL;
/*
* Dump a core file, after printing a warning message
* As with "quit()", try to use the "core_aux()" hook first.
*/
-void core(cptr str)
+void core(concptr str)
{
char *crash = NULL;
*/
while (s64b_cmp(A1val, A2val, B1, B2) == 1)
{
- s64b_LSHIFT(B1, B2);
+ s64b_LSHIFT(B1, B2, 1);
bit++;
}
s64b_sub(&A1val, &A2val, B1, B2);
}
- s64b_RSHIFT(B1, B2);
+ s64b_RSHIFT(B1, B2, 1);
bit--;
}
s64b_sub(A1, A2, tmp1, tmp2);
}
+/*!
+* @brief 符号なし32ビット整数のビット数を返す。
+* @param x ビット数を調べたい変数
+* @return ビット数
+*/
+int count_bits(BIT_FLAGS x)
+{
+ int n = 0;
+
+ if (x) do
+ {
+ n++;
+ } while (0 != (x = x&(x - 1)));
+
+ 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;
+}
\ No newline at end of file