STRING_TO_DECIMAL(3C) Standard C Library Functions STRING_TO_DECIMAL(3C)

## NAME

string_to_decimal, file_to_decimal, func_to_decimal - parse characters

into decimal record

## SYNOPSIS

#include <floatingpoint.h>

**void string_to_decimal**(**char ****__pc__, **int **__nmax__,

**int **__fortran_conventions__, **decimal_record ***__pd__,

**enum decimal_string_form ***__pform__, **char ****__pechar__);

**void func_to_decimal**(**char ****__pc__, **int **__nmax__,

**int **__fortran_conventions__, **decimal_record ***__pd__,

**enum decimal_string_form ***__pform__, **char ****__pechar__,

**int (***__pget__)(void), **int ***__pnread__, **int (***__punget__)(int __c__));

#include <stdio.h>

**void file_to_decimal**(**char ****__pc__, **int **__nmax__,

**int **__fortran_conventions__, **decimal_record ***__pd__,

**enum decimal_string_form ***__pform__, **char ****__pechar__,

**FILE ***__pf__, **int ***__pnread__);

## DESCRIPTION

These functions attempt to parse a numeric token from at most__nmax__

characters read from a string **__pc__, a file *__pf__, or function (*__pget__). They

set the decimal record *__pd__ to reflect the value of the numeric token

recognized and set *__pform__ and *__pechar__ to indicate its form.

The accepted forms for the numeric token consist of an initial, possibly

empty, sequence of white-space characters, as defined by isspace(3C),

followed by a subject sequence representing a numeric value, infinity, or

NaN. The subject sequence consists of an optional plus or minus sign

followed by one of the following:

o a non-empty sequence of decimal digits optionally containing a

decimal point character, then an optional exponent part

o one of INF or INFINITY, ignoring case

o one of NAN or NAN(__string__), ignoring case in the NAN part;

__string__ can be any sequence of characters not containing ')'

(right parenthesis) or '\0' (null).

The__fortran_conventions__ argument provides additional control over the set

of accepted forms. It must be one of the following values:

**0**

no Fortran conventions

**1**

Fortran list-directed input conventions

**2**

Fortran formatted input conventions, blanks are ignored

**3**

Fortran formatted input conventions, blanks are interpreted as

zeroes

When__fortran_conventions__ is zero, the decimal point character is the

current locale's decimal point character, and the exponent part consists

of the letter**E **or **e **followed by an optional sign and a non-empty string

of decimal digits.

When__fortran_conventions__ is non-zero, the decimal point character is "."

(period), and the exponent part consists of either a sign or one of the

letters**E**, **e**, **D**, **d**, **Q**, or **q **followed by an optional sign, then a non-

empty string of decimal digits.

When__fortran_conventions__ is **2 **or **3**, blanks can appear in the digit

strings for the integer, fraction, and exponent parts, between the

exponent delimiter and optional exponent sign, and after an INF,

INFINITY, NAN, or NAN(__string__). When __fortran_conventions__ is **2**, all blanks

are ignored. When__fortran_conventions__ is **3**, blanks in digit strings are

interpreted as zeros and other blanks are ignored.

The following table summarizes the accepted forms and shows the

corresponding values to which *__pform__ and __pd__->**fpclass **are set. Here __digits__

represents any string of decimal digits, "." (period) stands for the

decimal point character, and__exponent__ represents the exponent part as

defined above. Numbers in brackets refer to the notes following the

table.

form *__pform__ pd->**fpclass**

------------------------------------------------------------------

all white space [1]**whitespace_form fp_zero**

__digits__ **fixed_int_form fp_normal **[2]

__digits__. **fixed_intdot_form fp_normal **[2]

.__digits__ **fixed_dotfrac_form fp_normal **[2]

__digits__.__digits__ **fixed_intdotfrac_form fp_normal **[2]

__digits__ __exponent__ **floating_int_form fp_normal **[2]

__digits__. __exponent__ **floating_intdot_form fp_normal **[2]

.digits__exponent__ **floating_dotfrac_form fp_normal **[2]

__digits__.__digits__ __exponent__ **floating_intdotfrac_form fp_normal **[2]

INF**inf_form fp_infinity**

INFINITY**infinity_form fp_infinity**

NAN**nan_form fp_quiet**

NAN(__string__) **nanstring_form fp_quiet**

none of the above**invalid_form fp_signaling**

Notes:

1. The**whitespace_form **is accepted only when __fortran_conventions__

is 2 or 3 and is interpreted as zero.

2. For all numeric forms,__pd__->**fpclass **is set to **fp_normal **if any

non-zero digits appear in the integer or fraction parts, and

otherwise__pd__->**fpclass **is set to **fp_zero**.

If the accepted token has one of the numeric forms and represents a non-

zero number__x__, its significant digits are stored in __pd__->**ds**. Leading and

trailing zeroes and the radix point are omitted.__pd__->**sign **and

__pd__->**exponent **are set so that if __m__ is the integer represented by pd->**ds**,

-1**(pd->sign) * m * 10**(pd->exponent)

approximates__x__ to at least 511 significant digits. __pd__->**more **is set to 1

if this approximation is not exact (that is, the accepted token contains

additional non-zero digits beyond those copied to__pd__->**ds**) and to 0

otherwise.

If the accepted token has the NAN(__string__) form, up to 511 characters from

the string part are copied to__pd__->**ds**.

__pd__->**ds **is always terminated by a null byte, and __pd__->**ndigits **is set to the

length of the string stored in__pd__->**ds**.

On entry, *__pc__ points to the beginning of a character string buffer. The

**string_to_decimal() **function reads characters from this buffer until

either enough characters are read to delimit the accepted token (for

example, a null character marking the end of the string is found) or the

limit of__nmax__ characters is reached. The **file_to_decimal() **function reads

characters from the file *__pf__ and stores them in the buffer. The

**func_to_decimal() **function reads characters one at a time by calling the

function (*__pget__)() and stores them in the buffer; (*__pget__)() must return

integer values in the range -1 to 255, where -1 is interpreted as EOF and

0, ..., 255 are interpreted as**unsigned char **values. Both

**file_to_decimal() **and **func_to_decimal() **read characters until either

enough characters are read to delimit the accepted token, EOF is

encountered, or the limit of__nmax__ characters is reached. These functions,

therefore, typically read one or more additional characters beyond the

end of the accepted token and attempt to push back any excess characters

read. Provided that the__punget__ argument is not __NULL__, **func_to_decimal()**

pushes back characters one at a time by calling (*__punget__)(__c__), where __c__ is

an integer in the range 0 to 255 corresponding to a value previously read

via (*__pget__)(). After pushing back as many excess characters as possible,

**file_to_decimal() **and **func_to_decimal() **store a null byte in the buffer

following the last character read and not pushed back and set *__pnread__ to

the number of characters stored in the buffer prior to this null byte.

Since these functions can read up to__nmax__ characters, the buffer must be

large enough to hold__nmax__ + 1.

On exit, *__pc__ points to the next character in the buffer past the last one

that was accepted as part of the numeric token. If no valid token is

found, *__pc__ is unchanged. If **file_to_decimal() **and **func_to_decimal()**

successfully push back all unused characters, *__pc__ points to the null byte

stored in the buffer following the last character read and not pushed

back.

If the accepted token contains an exponent part, *__pechar__ is set to point

to the position in the buffer where the first character of the exponent

field is stored. If the accepted token does not contain an exponent

part, *__pechar__ is set to __NULL__.

## USAGE

If the_____**IOWRT **flag is set in *__pf__, **file_to_decimal() **reads characters

directly from the file buffer until a null character is found. (The

_____**IOWRT **flag should only be set when **file_to_decimal() **is called from

sscanf(3C).) Otherwise,**file_to_decimal() **uses getc_unlocked(3C), so it

is not MT-safe unless the caller holds the stream lock.

## ATTRIBUTES

See attributes(7) for descriptions of the following attributes:

+---------------+-------------------------+

|ATTRIBUTE TYPE | ATTRIBUTE VALUE |

+---------------+-------------------------+

|MT-Level | MT-Safe with exceptions |

+---------------+-------------------------+

## SEE ALSO

ctype(3C), decimal_to_floating(3C), getc_unlocked(3C), isspace(3C),

localeconv(3C), scanf(3C), setlocale(3C), strtod(3C), ungetc(3C),

attributes(7)

illumos October 1, 2003 STRING_TO_DECIMAL(3C)

string_to_decimal, file_to_decimal, func_to_decimal - parse characters

into decimal record

#include <floatingpoint.h>

#include <stdio.h>

These functions attempt to parse a numeric token from at most

characters read from a string **

set the decimal record *

recognized and set *

The accepted forms for the numeric token consist of an initial, possibly

empty, sequence of white-space characters, as defined by isspace(3C),

followed by a subject sequence representing a numeric value, infinity, or

NaN. The subject sequence consists of an optional plus or minus sign

followed by one of the following:

o a non-empty sequence of decimal digits optionally containing a

decimal point character, then an optional exponent part

o one of INF or INFINITY, ignoring case

o one of NAN or NAN(

(right parenthesis) or '\0' (null).

The

of accepted forms. It must be one of the following values:

no Fortran conventions

Fortran list-directed input conventions

Fortran formatted input conventions, blanks are ignored

Fortran formatted input conventions, blanks are interpreted as

zeroes

When

current locale's decimal point character, and the exponent part consists

of the letter

of decimal digits.

When

(period), and the exponent part consists of either a sign or one of the

letters

empty string of decimal digits.

When

strings for the integer, fraction, and exponent parts, between the

exponent delimiter and optional exponent sign, and after an INF,

INFINITY, NAN, or NAN(

are ignored. When

interpreted as zeros and other blanks are ignored.

The following table summarizes the accepted forms and shows the

corresponding values to which *

represents any string of decimal digits, "." (period) stands for the

decimal point character, and

defined above. Numbers in brackets refer to the notes following the

table.

form *

------------------------------------------------------------------

all white space [1]

.

.digits

INF

INFINITY

NAN

NAN(

none of the above

Notes:

1. The

is 2 or 3 and is interpreted as zero.

2. For all numeric forms,

non-zero digits appear in the integer or fraction parts, and

otherwise

If the accepted token has one of the numeric forms and represents a non-

zero number

trailing zeroes and the radix point are omitted.

-1**(pd->sign) * m * 10**(pd->exponent)

approximates

if this approximation is not exact (that is, the accepted token contains

additional non-zero digits beyond those copied to

otherwise.

If the accepted token has the NAN(

the string part are copied to

length of the string stored in

On entry, *

either enough characters are read to delimit the accepted token (for

example, a null character marking the end of the string is found) or the

limit of

characters from the file *

function (*

integer values in the range -1 to 255, where -1 is interpreted as EOF and

0, ..., 255 are interpreted as

enough characters are read to delimit the accepted token, EOF is

encountered, or the limit of

therefore, typically read one or more additional characters beyond the

end of the accepted token and attempt to push back any excess characters

read. Provided that the

pushes back characters one at a time by calling (*

an integer in the range 0 to 255 corresponding to a value previously read

via (*

following the last character read and not pushed back and set *

the number of characters stored in the buffer prior to this null byte.

Since these functions can read up to

large enough to hold

On exit, *

that was accepted as part of the numeric token. If no valid token is

found, *

successfully push back all unused characters, *

stored in the buffer following the last character read and not pushed

back.

If the accepted token contains an exponent part, *

to the position in the buffer where the first character of the exponent

field is stored. If the accepted token does not contain an exponent

part, *

If the

directly from the file buffer until a null character is found. (The

sscanf(3C).) Otherwise,

is not MT-safe unless the caller holds the stream lock.

See attributes(7) for descriptions of the following attributes:

+---------------+-------------------------+

|ATTRIBUTE TYPE | ATTRIBUTE VALUE |

+---------------+-------------------------+

|MT-Level | MT-Safe with exceptions |

+---------------+-------------------------+

ctype(3C), decimal_to_floating(3C), getc_unlocked(3C), isspace(3C),

localeconv(3C), scanf(3C), setlocale(3C), strtod(3C), ungetc(3C),

attributes(7)

illumos October 1, 2003 STRING_TO_DECIMAL(3C)