Profile

ys2310

Author:ys2310
2008年春にNew York Cityにあるふる〜い大学を卒業。


Categories


new postings


new comments


new trackbacks


monthly archeive


FC2ブログ 転職
DATE: CATEGORY:スポンサー広告
上記の広告は1ヶ月以上更新のないブログに表示されています。
新しい記事を書く事で広告が消せます。
| BLOG TOP |

abs

DATE: CATEGORY:C/C++ stdlib.h
整数算術関数
abs
ヘッダ #include "stdlib.h"
形 式 int abs(int j);
機 能 abs関数は、整数jの絶対値を計算する。結果の値がint型で表現できないときの動作は末定義である。
返却値 abs関数は、絶対値を返す。

static inline int abs(int j)
{
return j < 0 ? -j : j;
}

[Quote]:http://bohyoh.com
http://libc.blog47.fc2.com/blog-entry-57.html

| BLOG TOP |
DATE: CATEGORY:C/C++ stdlib.h
文字列変換関数
atoi
ヘッダ #include "stdlib.h"
形 式 int atoi(const char *nptr);
機 能 nptrが指す文字列の先頭部分をint型の表現に変換する。エラーが発生したときの動作を除くと、(int)strtol(nptr, (char **)NULL, 10)と等価である。
返却値 変換された値を返す。結果の値がint型で表現できないときの動作は定義されない(処理系に依存する)。

#include

int _space_sign(const char *s, const char **endptr)
{
while (isspace((unsigned char)*s))
++s;
int sign = 0;
switch (*s)
{
case '-':
sign = -1;
// fall through
case '+':
++s;
break;
}
*endptr = s;
return sign;
}

#include

int atoi(const char *s)
{
int sign = _space_sign(s, &s);
int result;
for (result = 0; isdigit((unsigned char)*s); s++)
result = result * 10 + *s - '0';
if (sign != 0)
result = -result;
return result;
}

[Quote]:http://bohyoh.com
http://libc.blog47.fc2.com/blog-entry-74.html

| BLOG TOP |

copyright © Manhattan life all rights reserved.Powered by FC2ブログ