CVTIA 3CW "26 February 2007" "mathcw-1.00"

Table of contents


NAME

cvtiaf, cvtia, cvtial, cvtiaw, cvtiaq, cvtiall, cvtiadf, cvtiad, cvtiadl, cvtiadll - convert any numeric string to number

SYNOPSIS

cc [ flags ] -I/usr/local/include file(s) -L/usr/local/lib -lmcw [ ... ]

#include <mathcw.h>
#include <cvticw.h>

extern float cvtiaf (const char *s, char **endptr);

extern double cvtia (const char *s, char **endptr);

extern long double cvtial (const char *s, char **endptr);

extern __float80 cvtiaw (const char *s, char **endptr);

extern __float128 cvtiaq (const char *s, char **endptr);

extern long_long_double cvtiall (const char *s, char **endptr);

extern decimal_float cvtiadf (const char *s, char **endptr);

extern decimal_double cvtiad (const char *s, char **endptr);

extern decimal_long_double cvtiadl (const char *s, char **endptr);

extern decimal_long_long_double cvtiadll (const char *s, char **endptr);

NB: Functions with prototypes containing underscores in type names may be available only with certain extended compilers.


DESCRIPTION

Convert a floating-point numeric string in any recognized format to a number. Acceptable formats include based-number, binary, octal, decimal, and hexadecimal, as well as character representations for Infinity and NaN. Examples of such numbers approximating the value pi (pi) are:

36@3.53i5g@e+0
+0b1.1001_0010_0001_1111_1011_011p+1
3.141593e+00
3.141593
+0o1.44417666p+1
0x1.921fb6p+1

As illustrated in the binary example, digits may be separated by a single underscore for enhanced readability.

The base and the exponent are always decimal values. Exponents in based numbers always represent powers of the base, whereas exponents in binary, hexadecimal, and octal floating-point numbers mean powers of two, and exponents in decimal floating-point numbers correspond to powers of ten.

Numbers may also contain valid C-style numeric-precision suffixes: f or F (float), l or L (long double), ll or LL (long_long_double), df or DF (decimal_float), dd or DD (decimal_double), dl or DL (decimal_long_double), and dll or DLL (decimal_long_long_double). However, the suffix does not determine the final numerical precision: that is set by the declared precision of the conversion function.

Lettercase is not significant in Infinity and NaN representations. Acceptable strings include ones like these:

Inf
-INFINITY
+INF
-NaN(0xfeedface)
NaN(0xfacade)
-NaN
+NaN
QNAN(0x1234)
+QNAN(0xacceded)
+QNAN
QNAN
SNaN(0xbead6789)
snan(0xbeef)
-snan(0XEFFACEABLE)
SNAN(cafe_feed)
-snan
snan
SNaN
SNAN

Although all IEEE 754 floating-point designs support a sign on NaNs, the sign has no significance.

In the current implementation, a parenthesized hexadecimal tag, optionally prefixed with 0x or 0X, and possibly containing underscore digit separators, is recognized in a NaN as long as the parentheses are balanced, and low-order bits of the tag are installed in the payload bits of the significand of the NaN.

QNaN (quiet NaN) and SNaN (signaling NaN) are distinguishable on most systems, except on the widely-used Intel IA-32 architecture, the Java Virtual Machine, and possibly also the Microsoft .NET Framework Common Language Infrastructure (CLI) virtual machine.

These functions can be used as replacements for the Standard C routines strtof(), strtod(), and strtold(), providing support for more input formats.


RETURN VALUES

Return the converted number, and if endptr is not NULL, set the pointer to which it points to the address of the character following the last character successfully converted. With suitable conventions for value delimiters, it is then possible to determine whether the value is erroneous or not.

The global variable errno defined in <errno.h> is set to EDOM for NaN conversion, and to ERANGE if a numeric string underflows or overflows. Conversion of Infinity strings does not set errno.


ERRORS

None.

SEE ALSO

cvtib(3CW), cvtid(3CW), cvtig(3CW), cvtih(3CW), cvtinf(3CW), cvtio(3CW), cvtnan(3CW), cvtob(3CW), cvtod(3CW), cvtog(3CW), cvtoh(3CW), cvton(3CW), cvtoo(3CW), printf(3CW), scanf(3CW), strtod(3), strtof(3), strtold(3).