ACSUtils Wiki

An ACS library for ZDoom-based ports

User Tools

Site Tools


number_parsing

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Last revisionBoth sides next revision
number_parsing [2017/03/21 16:05] – created korshunnumber_parsing [2017/03/21 16:19] korshun
Line 2: Line 2:
 ACSUtils provides functions to convert strings to numbers. ACSUtils provides functions to convert strings to numbers.
  
-Simple functions that simply return 0 on error:+===== Simple functions ===== 
 + 
 +These simply return 0 on error, b:
   * [[functions:atoi]]   * [[functions:atoi]]
   * [[functions:atof]]   * [[functions:atof]]
  
-Complex functions:+==== Examples ==== 
 + 
 +<code> 
 +atoi("123") -> 123 
 +atof("123.456") -> 123.456 
 +atoi("abc") -> 0 
 +</code> 
 + 
 +===== Complex functions ===== 
 +These return error status and result, and allow specifying an arbitrary base:
   * [[functions:ParseInt]]   * [[functions:ParseInt]]
   * [[functions:ParseFixed]]   * [[functions:ParseFixed]]
  
 +Error statuses are:
 +  * ''PARSENUMBER_SUCCESS'' -- number successfully parsed, you can use the result
 +  * ''PARSENUMBER_OVERFLOW'' -- the number is too big to fit into a variable, the result will be either [[constants:INT_MAX]] or [[constants:INT_MIN]].
 +  * ''PARSENUMBER_BADFORMAT'' - the number could not be parsed at all. You **may not** use the result. ''r2'' is unchanged.
 +
 +==== Examples ====
 +<code>
 +ParseInt("123", 0);
 +r1 -> PARSENUMBER_SUCCESS
 +r2 -> 123
 +
 +ParseInt("10", 8); // In base 8
 +r1 -> PARSENUMBER_SUCCESS
 +r2 -> 8
  
 +ParseInt("999999999
number_parsing.txt · Last modified: 2017/03/21 16:28 by korshun