並び順

ブックマーク数

期間指定

  • から
  • まで

1 - 1 件 / 1件

新着順 人気順

atoiの検索結果1 - 1 件 / 1件

  • atoi関数のかしこい実装 - yohhoyの日記

    C標準ライブラリ Muslのatoi関数実装 では、符号付き整数オーバーフロー回避のため負数範囲で10進数値を減算してゆき最後に符号反転を行っている。 int atoi(const char *s) { int n=0, neg=0; while (isspace(*s)) s++; switch (*s) { case '-': neg=1; case '+': s++; } /* Compute n as a negative number to avoid overflow on INT_MIN */ while (isdigit(*s)) n = 10 * n - (*s++ - '0'); return neg ? n : -n; } C言語の符号付き整数型(int)では “2の補数” 表現が用いられるため*1、最大値INT_MAXより最小値INT_MINの絶対値が 1 だけ大き

      atoi関数のかしこい実装 - yohhoyの日記
    1