plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

atof.3 (3262B)


      1 .TH ATOF 3
      2 .SH NAME
      3 atof, atoi, atol, atoll, charstod, strtod, strtol, strtoll, strtoul, strtoull \- convert text to numbers
      4 .SH SYNOPSIS
      5 .B #include <u.h>
      6 .br
      7 .B #include <libc.h>
      8 .PP
      9 .nf
     10 .ta \w'\fLdouble 'u
     11 .B
     12 double	atof(char *nptr)
     13 .PP
     14 .B
     15 int	atoi(char *nptr)
     16 .PP
     17 .B
     18 long	atol(char *nptr)
     19 .PP
     20 .B
     21 vlong	atoll(char *nptr)
     22 .PP
     23 .B
     24 double	charstod(int (*f)(void *), void *a)
     25 .PP
     26 .B
     27 double	strtod(char *nptr, char **rptr)
     28 .PP
     29 .B
     30 long	strtol(char *nptr, char **rptr, int base)
     31 .PP
     32 .B
     33 vlong	strtoll(char *nptr, char **rptr, int base)
     34 .PP
     35 .B
     36 ulong	strtoul(char *nptr, char **rptr, int base)
     37 .PP
     38 .B
     39 vlong	strtoull(char *nptr, char **rptr, int base)
     40 .fi
     41 .SH DESCRIPTION
     42 .IR Atof ,
     43 .IR atoi ,
     44 .IR atol ,
     45 and
     46 .I atoll
     47 convert a string pointed to by
     48 .I nptr
     49 to floating, integer, long integer, and long long integer
     50 .RB ( vlong )
     51 representation respectively.
     52 The first unrecognized character ends the string.
     53 Leading C escapes are understood, as in
     54 .I strtol
     55 with
     56 .I base
     57 zero (described below).
     58 .PP
     59 .I Atof
     60 recognizes an optional string of tabs and spaces,
     61 then an optional sign, then
     62 a string of digits optionally containing a decimal
     63 point, then an optional 
     64 .L e
     65 or 
     66 .L E
     67 followed
     68 by an optionally signed integer.
     69 .PP
     70 .I Atoi
     71 and
     72 .I atol
     73 recognize an optional string of tabs and spaces,
     74 then an optional sign, then a string of
     75 decimal digits.
     76 .PP
     77 .IR Strtod ,
     78 .IR strtol ,
     79 .IR strtoll ,
     80 .IR strtoul ,
     81 and
     82 .I strtoull
     83 behave similarly to 
     84 .I atof
     85 and
     86 .I atol
     87 and, if
     88 .I rptr
     89 is not zero, set
     90 .I *rptr
     91 to point to the input character
     92 immediately after the string converted.
     93 .PP
     94 .IR Strtol ,
     95 .IR strtoll ,
     96 .IR strtoul ,
     97 and
     98 .IR strtoull
     99 interpret the digit string in the specified
    100 .IR base ,
    101 from 2 to 36,
    102 each digit being less than the base.
    103 Digits with value over 9 are represented by letters,
    104 a-z or A-Z.
    105 If
    106 .I base
    107 is 0, the input is interpreted as an integral constant in
    108 the style of C (with no suffixed type indicators):
    109 numbers are octal if they begin with
    110 .LR 0 ,
    111 hexadecimal if they begin with
    112 .L 0x
    113 or
    114 .LR 0X ,
    115 otherwise decimal.
    116 .PP
    117 .I Charstod
    118 interprets floating point numbers in the manner of
    119 .IR atof ,
    120 but gets successive characters by calling
    121 .BR (*\fIf\fP)(a) .
    122 The last call to
    123 .I f
    124 terminates the scan, so it must have returned a character that
    125 is not a legal continuation of a number.
    126 Therefore, it may be necessary to back up the input stream one character
    127 after calling
    128 .IR charstod .
    129 .SH SOURCE
    130 .B \*9/src/lib9
    131 .SH SEE ALSO
    132 .MR fscanf (3)
    133 .SH DIAGNOSTICS
    134 Zero is returned if the beginning of the input string is not
    135 interpretable as a number; even in this case,
    136 .I rptr
    137 will be updated.
    138 .br
    139 These routines set
    140 .IR errstr .
    141 .SH BUGS
    142 .I Atoi
    143 and
    144 .I atol
    145 accept octal and hexadecimal numbers in the style of C,
    146 contrary to the ANSI specification.
    147 .PP
    148 .IR Atof ,
    149 .IR strtod ,
    150 .IR strtol ,
    151 .IR strtoul ,
    152 .IR strtoll ,
    153 and
    154 .IR strtoull
    155 are not provided:
    156 they are expected to be provided by the underlying system.
    157 .PP
    158 Because they are implemented in the fmt library,
    159 .I charstod
    160 and
    161 .I strtod
    162 are preprocessor macros defined as
    163 .I fmtcharstod
    164 and
    165 .IR fmtstrtod .
    166 .PP
    167 To avoid name conflicts with the underlying system,
    168 .IR atoi ,
    169 .IR atol ,
    170 and
    171 .I atoll
    172 are preprocessor macros defined as
    173 .IR p9atoi ,
    174 .IR p9atol ,
    175 and
    176 .IR p9atoll ;
    177 see
    178 .MR intro (3) .