strtod

STRTOD(3)                  Linux Programmer's Manual                 STRTOD(3)



åå
       strtod, strtof, strtold - ASCII æååãæµ®åå°æ°ç¹å®æ°ã«å¤æãã

æ¸å¼
       #include <stdlib.h>

       double strtod(const char *nptr, char **endptr);
       float strtof(const char *nptr, char **endptr);
       long double strtold(const char *nptr, char **endptr);

   glibc åãã®æ©è½æ¤æ»ãã¯ãã®è¦ä»¶ (feature_test_macros(7)  åç§):

       strtof(), strtold():
           _XOPEN_SOURCE >= 600 || _ISOC99_SOURCE ||
           _POSIX_C_SOURCE >= 200112L;
           ã¾ã㯠cc -std=c99

説æ
       strtod(), strtof(), strtold()  é¢æ°ã¯ã nptr ãæã示ãæååã®ã¯ããã®é¨åã
       double, float, long double åã®å¤ã«ããããå¤æããã

       å¥åããæåå (ã®åé é¨å) ã¯ä»¥ä¸ã®å½¢å¼ãæå¾ããã¦ããã åé ã«ãã¯ã¤ãã¹ãã¼ã¹ã
       次ã«ãã©ã¹ ('+') ã¾ãã¯ãã¤ãã¹ ('-') ã®è¨å·ã ãã®å¾ã« (i) 10 é²æ°ã(ii) 16
       é²æ°ã(iii) ç¡éã (iv) NAN (è¨ç®ã§ããªãæ°ãnot-a-number) ã®ããããããã
       (ãã¯ã¤ãã¹ãã¼ã¹ã符å·ã¯çç¥å¯è½ã ãã¯ã¤ãã¹ãã¼ã¹ã¯ isspace(3) ã§èå¥ããã)ã

       10 é²æ° 㯠1 æå以ä¸ã® 10 é²ã®æ°åã®åãããªãã åºã表ãæå (radix charater)
       (å°æ°ç¹ããã±ã¼ã«ã«ä¾åããããé常㯠'.') ãå«ã¾ãããã¨ãããã ãã®å¾ã« 10
       é²ã®ææ°é¨ãç¶ãã¦ãè¯ãã 10 é²ã®ææ°é¨ã¯ 'E' ã¾ã㯠'e' ã¨ããã®å¾ã«ç½®ãããæ‐
       £è² è¨å· (çç¥å¯)ã ããã³ãã®å¾ã«ç¶ã 1 æå以ä¸ã® 10 é²ã®æ°åã®åãããªãã 10
       ã®ä½ä¹ã§ãããã表ãã

       16 é²æ° ã¯ã"0x" ã¾ã㯠"0X" ã¨ãã®å¾ã«ç¶ã 1 æå以ä¸ã® 16 é²ã®æ°åã®åãããªãã
       åºã表ãæåãå«ã¾ãããã¨ãããã ãã®å¾ã« 2 é²ã®ææ°é¨ãç¶ãã¦ãè¯ãã 2 é²ã®ææ°é¨ã¯
       'P' ã¾ã㯠'p' ã¨ããã®å¾ã«ç½®ãããæ£è² è¨å· (çç¥å¯)ã ããã³ãã®å¾ã«ç¶ã 1 æå‐
       以ä¸ã® 10 é²ã®æ°åã®åããæ§æããã 2 ã®ä½ä¹ã§ãããã表ãã åºã表ãæå㨠2
       é²ã®ææ°é¨ã¯ãã©ã¡ããä¸æ¹ããåå¨ãã¦ã¯ãªããªãã

       ç¡é 㯠"INF" ã¾ã㯠"INFINITY" ã§è¡¨ããã大æåå°æåã¯åºå¥ãããªãã

       NAN 㯠"NAN" (大æåå°æåã¯åºå¥ãããªã) ã§è¡¨ããã ãã®å¾ã« '(' æåå ')'
       ãç¶ãå ´åãããã ãã®æååã¯å®è£ã«ä¾åãã NAN ãæå®ããã

è¿ãå¤
       ãããã®é¢æ°ã¯ãå¤æãããå¤ãããã°ããããè¿ãã

       endptr ã NULL ã§ãªãã¨ãã¯ãå¤æã«ä½¿ãããæçµæåã®æ¬¡ã®æåã¸ã®ãã¤ã³ã¿ã¼ã endptr
       ã§åç§ãããå ´æã¸ä¿åãããã

       å¤æãè¡ãããªãã£ãã¨ãã«ã¯ 0 ãè¿ãããã㦠endptr ãåç§ãã¦ããå ´æã« nptr ã®å¤
       (å¤æ対象ã§ããæååã®éå§ã¢ãã¬ã¹) ãä¿åãããã

       æ£ããå½¢å¼ã®æ°å¤æååã§ããããå¤æçµæããªã¼ãã¼ããã¼ãèµ·ãããå ´å
       ã«ã¯ããã©ã¹ã¾ãã¯ãã¤ãã¹ã® HUGE_VAL (HUGE_VALF, HUGE_VALL)  ãè¿ã
       (å¤ã®ç¬¦å·ã«ãã)ã ERANGE ã errno ã«ä»£å¥ããããå¤æçµæãã¢ã³ãã¼ãã‐
       ã¼ãèµ·ãããå ´åã«ã¯ 0 ãè¿ãã ERANGE ã errno ã«ä»£å¥ãããã

ã¨ã©ã¼
       ERANGE ãªã¼ãã¼ããã¼ã¾ãã¯ã¢ã³ãã¼ããã¼ãèµ·ãã£ãã

æºæ
       C89 ã§ã¯ strtod()  ããC99 ã§ã¯æ®ãã® 2 ã¤ã®é¢æ°ãè¨è¿°ããã¦ããã

注æ
       æåã失æã©ã¡ãã®å ´åã§ã 0 ãè¿ãå¯è½æ§ãããã®ã§ã ããã°ã©ã ã¯å¼ã³åºãåã« errno ã
       0 ã«è¨å®ããå¼ã³åºãå¾ã« errno ã 0
       以å¤ã®å¤ãã©ããã確èªãã¨ã©ã¼ãçºçãããã©ãããå¤æãã å¿è¦ãããã

ä¾
       strtol(3)  ã®ããã¥ã¢ã«ãã¼ã¸ã®ä¾ãåç§ã
       ãã®ãã¼ã¸ã§èª¬æããé¢æ°ã®ä½¿ç¨æ¹æ³ãåæ§ã§ããã

é¢é£é ç®
       atof(3), atoi(3), atol(3), strtol(3), strtoul(3)

ãã®ææ¸ã«ã¤ãã¦
       ãã® man ãã¼ã¸ã¯ Linux man-pages ããã¸ã§ã¯ãã®ãªãªã¼ã¹ 3.51 ã®ä¸é¨
       ã§ãããããã¸ã§ã¯ãã®èª¬æã¨ãã°å ±åã«é¢ããæå ±ã¯
       http://www.kernel.org/doc/man-pages/ ã«æ¸ããã¦ããã



Linux                             2010-09-20                         STRTOD(3)