Changeset 087c8798 in mainline for uspace/lib/posix/stdlib
- Timestamp:
- 2011-07-20T19:30:30Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 102a729
- Parents:
- fc3680e
- Location:
- uspace/lib/posix/stdlib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/posix/stdlib/strtol.c
rfc3680e r087c8798 30 30 * @{ 31 31 */ 32 /** @file 32 /** @file Backend for integer conversions. 33 33 */ 34 34 … … 42 42 #include "../errno.h" 43 43 44 // TODO: documentation 45 44 /** 45 * Decides whether a digit belongs to a particular base. 46 * 47 * @param c Character representation of the digit. 48 * @param base Base against which the digit shall be tested. 49 * @return True if the digit belongs to the base, false otherwise. 50 */ 46 51 static inline bool is_digit_in_base(int c, int base) 47 52 { … … 54 59 } 55 60 61 /** 62 * Derive a digit from its character representation. 63 * 64 * @param c Character representation of the digit. 65 * @param base Base into which the digit belongs to. 66 * @return Digit value represented by an integer. 67 */ 56 68 static inline int get_digit_in_base(int c, int base) 57 69 { … … 63 75 } 64 76 77 /** 78 * Backend for all integer conversion functions. Can be configured by arguments 79 * to convert both signed and unsigned integers of various sizes. 80 * 81 * @param nptr Input string. 82 * @param endptr If non-NULL, *endptr is set to the position of the first 83 * unrecognized character. 84 * @param base Expected base of the string representation. 85 * @param min_value Lower bound for the resulting conversion. 86 * @param max_value Upper bound for the resulting conversion. 87 * @param out_negative Either NULL for unsigned conversion or a pointer to the 88 * bool variable into which shall be placed the negativity of the resulting 89 * converted value. 90 * @return Result of the conversion. 91 */ 65 92 static inline unsigned long long internal_strtol( 66 93 const char *restrict nptr, char **restrict endptr, int base, … … 188 215 } 189 216 217 /** 218 * Convert a string to an integer. 219 * 220 * @param nptr Input string. 221 * @return Result of the conversion. 222 */ 190 223 int posix_atoi(const char *nptr) 191 224 { … … 197 230 } 198 231 232 /** 233 * Convert a string to a long integer. 234 * 235 * @param nptr Input string. 236 * @return Result of the conversion. 237 */ 199 238 long posix_atol(const char *nptr) 200 239 { … … 206 245 } 207 246 247 /** 248 * Convert a string to a long long integer. 249 * 250 * @param nptr Input string. 251 * @return Result of the conversion. 252 */ 208 253 long long posix_atoll(const char *nptr) 209 254 { … … 215 260 } 216 261 262 /** 263 * Convert a string to a long integer. 264 * 265 * @param nptr Input string. 266 * @param endptr Pointer to the final part of the string which 267 * was not used for conversion. 268 * @param base Expected base of the string representation. 269 * @return Result of the conversion. 270 */ 217 271 long posix_strtol(const char *restrict nptr, char **restrict endptr, int base) 218 272 { … … 224 278 } 225 279 280 /** 281 * Convert a string to a long long integer. 282 * 283 * @param nptr Input string. 284 * @param endptr Pointer to the final part of the string which 285 * was not used for conversion. 286 * @param base Expected base of the string representation. 287 * @return Result of the conversion. 288 */ 226 289 long long posix_strtoll( 227 290 const char *restrict nptr, char **restrict endptr, int base) … … 234 297 } 235 298 299 /** 300 * Convert a string to an unsigned long integer. 301 * 302 * @param nptr Input string. 303 * @param endptr Pointer to the final part of the string which 304 * was not used for conversion. 305 * @param base Expected base of the string representation. 306 * @return Result of the conversion. 307 */ 236 308 unsigned long posix_strtoul( 237 309 const char *restrict nptr, char **restrict endptr, int base) … … 243 315 } 244 316 317 /** 318 * Convert a string to a an unsigned long long integer. 319 * 320 * @param nptr Input string. 321 * @param endptr Pointer to the final part of the string which 322 * was not used for conversion. 323 * @param base Expected base of the string representation. 324 * @return Result of the conversion. 325 */ 245 326 unsigned long long posix_strtoull( 246 327 const char *restrict nptr, char **restrict endptr, int base) … … 249 330 } 250 331 251 252 332 /** @} 253 333 */ 254 -
uspace/lib/posix/stdlib/strtold.c
rfc3680e r087c8798 30 30 * @{ 31 31 */ 32 /** @file 32 /** @file Backend for floating point conversions. 33 33 */ 34 34 … … 55 55 #endif 56 56 57 // TODO: clean up , documentation57 // TODO: clean up 58 58 59 59 // FIXME: ensure it builds and works on all platforms … … 116 116 }; 117 117 118 /** 119 * Decides whether the argument is still in range representable by 120 * long double or not. 121 * 122 * @param num Floating point number to be checked. 123 * @return True if the argument is out of range, false otherwise. 124 */ 118 125 static inline bool out_of_range(long double num) 119 126 { … … 127 134 * @param base Number to be multiplied. 128 135 * @param exponent Base 5 exponent. 129 * @return base multiplied by 5**exponent 136 * @return base multiplied by 5**exponent. 130 137 */ 131 138 static long double mul_pow5(long double base, int exponent) … … 173 180 * @param base Number to be multiplied. 174 181 * @param exponent Base 2 exponent. 175 * @return base multiplied by 2**exponent 182 * @return base multiplied by 2**exponent. 176 183 */ 177 184 static long double mul_pow2(long double base, int exponent) … … 212 219 } 213 220 214 221 /** 222 * Convert decimal string representation of the floating point number. 223 * Function expects the string pointer to be already pointed at the first 224 * digit (i.e. leading optional sign was already consumed by the caller). 225 * 226 * @param sptr Pointer to the storage of the string pointer. Upon successful 227 * conversion, the string pointer is updated to point to the first 228 * unrecognized character. 229 * @return An approximate representation of the input floating-point number. 230 */ 215 231 static long double parse_decimal(const char **sptr) 216 232 { … … 315 331 } 316 332 333 /** 334 * Derive a hexadecimal digit from its character representation. 335 * 336 * @param ch Character representation of the hexadecimal digit. 337 * @return Digit value represented by an integer. 338 */ 317 339 static inline int hex_value(char ch) 318 340 { … … 325 347 326 348 /** 349 * Get the count of leading zero bits up to the maximum of 3 zero bits. 350 * 327 351 * @param val Integer value. 328 352 * @return How many leading zero bits there are. (Maximum is 3) … … 339 363 } 340 364 365 /** 366 * Convert hexadecimal string representation of the floating point number. 367 * Function expects the string pointer to be already pointed at the first 368 * digit (i.e. leading optional sign and 0x prefix were already consumed 369 * by the caller). 370 * 371 * @param sptr Pointer to the storage of the string pointer. Upon successful 372 * conversion, the string pointer is updated to point to the first 373 * unrecognized character. 374 * @return Representation of the input floating-point number. 375 */ 341 376 static long double parse_hexadecimal(const char **sptr) 342 377 { … … 567 602 /** @} 568 603 */ 569
Note:
See TracChangeset
for help on using the changeset viewer.