.\" Copyright (c) 1990, 1991 The Regents of the University of California. .\" All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by .\" the American National Standards Committee X3, on Information .\" Processing Systems. .\" .\" %%%LICENSE_START(BSD_4_CLAUSE_UCB) .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by the University of .\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" %%%LICENSE_END .\" .\" @(#)strtod.3 5.3 (Berkeley) 6/29/91 .\" .\" Modified Sun Aug 21 17:16:22 1994 by Rik Faith (faith@cs.unc.edu) .\" Modified Sat May 04 19:34:31 MET DST 1996 by Michael Haardt .\" (michael@cantor.informatik.rwth-aachen.de) .\" Added strof, strtold, aeb, 2001-06-07 .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" Japanese Version Copyright (c) 1998-1999 .\" Michihide Hotta and NAKANO Takeo all rights reserved. .\" Translated Fri Jun 26 1998 by Yasushi Shoji .\" Updated & Modified Sun Mar 14 1999 by NAKANO Takeo .\" Updated & Modified Sun Jul 1 16:59:53 JST 2001 .\" by Yuichi SATO .\" Updated & Modified 2006-07-20, .\" Akihiro MOTOKI , LDP v2.36 .\" .TH STRTOD 3 2020\-11\-01 Linux "Linux Programmer's Manual" .SH 名前 strtod, strtof, strtold \- ASCII 文字列を浮動小数点実数に変換する .SH 書式 \fB#include \fP .PP \fBdouble strtod(const char *\fP\fInptr\fP\fB, char **\fP\fIendptr\fP\fB);\fP .br \fBfloat strtof(const char *\fP\fInptr\fP\fB, char **\fP\fIendptr\fP\fB);\fP .br \fBlong double strtold(const char *\fP\fInptr\fP\fB, char **\fP\fIendptr\fP\fB);\fP .PP .RS -4 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照): .RE .ad l .PP \fBstrtof\fP(), \fBstrtold\fP(): .RS 4 _ISOC99_SOURCE || _POSIX_C_SOURCE\ >=\ 200112L .RE .ad .SH 説明 \fBstrtod\fP(), \fBstrtof\fP(), \fBstrtold\fP() 関数は、 \fInptr\fP が指し示す文字列のはじめの部分を \fIdouble\fP, \fIfloat\fP, \fIlong double\fP 型の値にそれぞれ変換する。 .PP 入力する文字列 (の先頭部分) は以下の形式が期待されている。 先頭にホワイトスペース、 次にプラス (\(aq+\(aq) またはマイナス (\(aq\-\(aq) の記号、 その後に (i) 10 進数、(ii) 16 進数、(iii) 無限、 (iv) NAN (計算できない数、not\-a\-number) のいずれかがある (ホワイトスペース、符号は省略可能。 ホワイトスペースは \fBisspace\fP(3) で識別される)。 .PP \fI10 進数\fP は 1 文字以上の 10 進の数字の列からなり、 基を表す文字 (radix charater) (小数点。ロケールに依存するが、通常は \(aq.\(aq) が含まれることもある。 この後に 10 進の指数部が続いても良い。 10 進の指数部は \(aqE\(aq または \(aqe\(aq と、その後に置かれる正負記号 (省略可)、 およびその後に続く 1 文字以上の 10 進の数字の列からなり、 10 の何乗であるかを表す。 .PP \fI16 進数\fP は、"0x" または "0X" とその後に続く 1 文字以上の 16 進の数字の列からなり、 基を表す文字が含まれることもある。 この後に 2 進の指数部が続いても良い。 2 進の指数部は \(aqP\(aq または \(aqp\(aq と、その後に置かれる正負記号 (省略可)、 およびその後に続く 1 文字以上の 10 進の数字の列から構成され、 2 の何乗であるかを表す。 基を表す文字と 2 進の指数部は、どちらか一方しか存在してはならない。 .PP \fI無限\fP は "INF" または "INFINITY" で表され、大文字小文字は区別されない。 .PP \fINAN\fP は "NAN" (大文字小文字は区別されない) で表され、 その後に文字列 \fI(n\-char\-sequence)\fP が続く場合もある。 \fI(n\-char\-sequence)\fP は実装に依存する NAN の型を指定する。 .SH 返り値 これらの関数は、変換された値があれば、それを返す。 .PP \fIendptr\fP が NULL でないときは、変換に使われた最終文字の次の文字へのポインターが \fIendptr\fP で参照される場所へ保存される。 .PP If no conversion is performed, zero is returned and (unless \fIendptr\fP is null) the value of \fInptr\fP is stored in the location referenced by \fIendptr\fP. .PP If the correct value would cause overflow, plus or minus \fBHUGE_VAL\fP, \fBHUGE_VALF\fP, or \fBHUGE_VALL\fP is returned (according to the return type and sign of the value), and \fBERANGE\fP is stored in \fIerrno\fP. .PP If the correct value would cause underflow, a value with magnitude no larger than \fBDBL_MIN\fP, \fBFLT_MIN\fP, or \fBLDBL_MIN\fP is returned and \fBERANGE\fP is stored in \fIerrno\fP. .SH エラー .TP \fBERANGE\fP オーバーフローまたはアンダーフローが起こった。 .SH 属性 この節で使用されている用語の説明については、 \fBattributes\fP(7) を参照。 .TS allbox; lbw29 lb lb l l l. インターフェース 属性 値 T{ \fBstrtod\fP(), \fBstrtof\fP(), \fBstrtold\fP() T} Thread safety MT\-Safe locale .TE .SH 準拠 POSIX.1\-2001, POSIX.1\-2008, C99. .PP \fBstrtod\fP() was also described in C89. .SH 注意 成功、失敗どちらの場合でも 0 を返す可能性があるので、 プログラムは呼び出す前に \fIerrno\fP を 0 に設定し、呼び出し後に \fIerrno\fP が 0 以外の値かどうかを確認しエラーが発生したかどうかを判断する 必要がある。 .PP .\" From glibc 2.8's stdlib/strtod_l.c: .\" We expect it to be a number which is put in the .\" mantissa of the number. .\" It looks as though at least FreeBSD (according to the manual) does .\" something similar. .\" C11 says: "An implementation may use the n-char sequence to determine .\" extra information to be represented in the NaN's significant." glibc の実装では、"NAN" の後ろに置くことができる \fIn\-char\-sequence\fP は、整数値として解釈される (基数の 8 や 16 を示す '0' や '0x' を接頭辞として付けることができる)。 この整数値は返り値の仮数部として使われる。 .SH 例 \fBstrtol\fP(3) のマニュアルページの例を参照。 このページで説明した関数の使用方法も同様である。 .SH 関連項目 \fBatof\fP(3), \fBatoi\fP(3), \fBatol\fP(3), \fBnan\fP(3), \fBnanf\fP(3), \fBnanl\fP(3), \fBstrfromd\fP(3), \fBstrtol\fP(3), \fBstrtoul\fP(3) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は \%https://www.kernel.org/doc/man\-pages/ に書かれている。