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

Both sides previous revisionPrevious revision
Next revision
Previous revision
number_parsing [2017/03/21 16:09] korshunnumber_parsing [2017/03/21 16:28] (current) korshun
Line 1: Line 1:
 ====== Number parsing ====== ====== Number parsing ======
 ACSUtils provides functions to convert strings to numbers. ACSUtils provides functions to convert strings to numbers.
 +
 +===== Bases =====
 +The parsed numbers can be written in any base from 2 to 36. In bases over 10, letters of the alphabet are used as digits.
 +
 +If a base is not explicitly specified or is set to 0, base prefixes can be used:
 +  * ''0x'' – base 16
 +  * ''0o'' – base 8
 +  * ''0b'' – base 2
 +
 +For example, ''%%"0xFF"%%'' is parsed as 256.
 +
 +If no base prefix is present, base 10 is used by default
 +
 +If a base is specified when parsing the number, base prefixes are **not** supported and their presence is treated as error.
 +
 +===== Errors =====
 +The following errors can happen while parsing a number:
 +  * ''PARSENUMBER_SUCCESS'' -- no error
 +  * ''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.
 +
 +
  
 ===== Simple functions ===== ===== Simple functions =====
  
-These simply return 0 on error:+These simply return 0 on error, b:
   * [[functions:atoi]]   * [[functions:atoi]]
   * [[functions:atof]]   * [[functions:atof]]
 +
 +==== Examples ====
  
 <code> <code>
Line 20: Line 44:
  
 Error statuses are: Error statuses are:
-  * ''PARSENUMBER_SUCCESS'' -- number successfully parsedyou can use the result +   
-  * ''PARSENUMBER_OVERFLOW'' -- the number is too big to fit into a variablethe result will be either [[constants:INT_MAX]] or [[constants:INT_MIN]]. +==== Examples ==== 
-  * ''PARSENUMBER_BADFORMAT'' the number could not be parsed at all. You **may not** use the result. ''r2'' is unchanged.+<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