atof 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. .TH ATOF 2
  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(const char *nptr, char **rptr, int base)
  31. .PP
  32. .B
  33. vlong strtoll(const char *nptr, char **rptr, int base)
  34. .PP
  35. .B
  36. ulong strtoul(const char *nptr, char **rptr, int base)
  37. .PP
  38. .B
  39. uvlong strtoull(const 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 /sys/src/libc/port
  131. .SH SEE ALSO
  132. .IR fscanf (2)
  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. .SH BUGS
  139. .I Atoi,
  140. .I atol,
  141. and
  142. .I atoll
  143. accept octal and hexadecimal numbers in the style of C,
  144. contrary to the ANSI specification.