1 .\" Copyright (c) 1990, 1991 The Regents of the University of California.
2 .\" All rights reserved.
4 .\" This code is derived from software contributed to Berkeley by
5 .\" the American National Standards Committee X3, on Information
6 .\" Processing Systems.
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\" notice, this list of conditions and the following disclaimer.
13 .\" 2. Redistributions in binary form must reproduce the above copyright
14 .\" notice, this list of conditions and the following disclaimer in the
15 .\" documentation and/or other materials provided with the distribution.
16 .\" 3. All advertising materials mentioning features or use of this software
17 .\" must display the following acknowledgement:
18 .\" This product includes software developed by the University of
19 .\" California, Berkeley and its contributors.
20 .\" 4. Neither the name of the University nor the names of its contributors
21 .\" may be used to endorse or promote products derived from this software
22 .\" without specific prior written permission.
24 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 .\" @(#)strtod.3 5.3 (Berkeley) 6/29/91
38 .\" Modified Sun Aug 21 17:16:22 1994 by Rik Faith (faith@cs.unc.edu)
39 .\" Modified Sat May 04 19:34:31 MET DST 1996 by Michael Haardt
40 .\" (michael@cantor.informatik.rwth-aachen.de)
41 .\" Added strof, strtold, aeb, 2001-06-07
43 .\" Japanese Version Copyright (c) 1998-1999
44 .\" Michihide Hotta and NAKANO Takeo all rights reserved.
45 .\" Translated Fri Jun 26 1998 by Yasushi Shoji <yashi@yashi.com>
46 .\" Updated & Modified Sun Mar 14 1999 by NAKANO Takeo <nakano@apm.seikei.ac.jp>
47 .\" Updated & Modified Sun Jul 1 16:59:53 JST 2001
48 .\" by Yuichi SATO <ysato@h4.dion.ne.jp>
49 .\" Updated & Modified 2006-07-20,
50 .\" Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.36
52 .TH STRTOD 3 2010-00-20 "Linux" "Linux Programmer's Manual"
54 strtod, strtof, strtold \- ASCII 文字列を浮動小数点実数に変換する
56 .B #include <stdlib.h>
58 .BI "double strtod(const char *" nptr ", char **" endptr );
60 .BI "float strtof(const char *" nptr ", char **" endptr );
62 .BI "long double strtold(const char *" nptr ", char **" endptr );
66 .RB ( feature_test_macros (7)
74 _XOPEN_SOURCE\ >=\ 600 || _ISOC99_SOURCE ||
75 _POSIX_C_SOURCE\ >=\ 200112L;
93 入力する文字列 (の先頭部分) は以下の形式が期待されている。
95 次にプラス (\(aq+\(aq) またはマイナス (\(aq\-\(aq) の記号、
96 その後に (i) 10 進数、(ii) 16 進数、(iii) 無限、
97 (iv) NAN (計算できない数、not-a-number) のいずれかがある
104 は 1 文字以上の 10 進の数字の列からなり、
105 基を表す文字 (radix charater)
106 (小数点。ロケールに依存するが、通常は \(aq.\(aq) が含まれることもある。
107 この後に 10 進の指数部が続いても良い。
108 10 進の指数部は \(aqE\(aq または \(aqe\(aq と、その後に置かれる正負記号 (省略可)、
109 およびその後に続く 1 文字以上の 10 進の数字の列からなり、
113 は、"0x" または "0X" とその後に続く 1 文字以上の 16 進の数字の列からなり、
116 2 進の指数部は \(aqP\(aq または \(aqp\(aq と、その後に置かれる正負記号 (省略可)、
117 およびその後に続く 1 文字以上の 10 進の数字の列から構成され、
119 基を表す文字と 2 進の指数部は、どちらか一方しか存在してはならない。
122 は "INF" または "INFINITY" で表され、大文字小文字は区別されない。
125 は "NAN" (大文字小文字は区別されない) で表され、
126 その後に \(aq(\(aq 文字列 \(aq)\(aq が続く場合もある。
127 この文字列は実装に依存する NAN を指定する。
128 .\" From glibc 2.8's stdlib/strtod_l.c:
129 .\" We expect it to be a number which is put in the
130 .\" mantissa of the number.
132 これらの関数は、変換された値があれば、それを返す。
135 が NULL でないときは、変換に使われた最終文字の次の文字へのポインターが
139 変換が行われなかったときには 0 が返る。そして
143 の値 (変換対象である文字列の開始アドレス) が保存される。
145 正しい形式の数値文字列であるが、変換結果がオーバーフローを起こした場合
154 に代入される。変換結果がアンダーフローを起こした場合には 0 が返り、
162 オーバーフローまたはアンダーフローが起こった。
166 が、C99 では残りの 2 つの関数が記述されている。
168 成功、失敗どちらの場合でも 0 を返す可能性があるので、
173 が 0 以外の値かどうかを確認しエラーが発生したかどうかを判断する
178 このページで説明した関数の使用方法も同様である。