ACSUtils Wiki

An ACS library for ZDoom-based ports

User Tools

Site Tools


functions:parseint

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
functions:parseint [2017/04/17 15:30] korshunfunctions:parseint [2017/04/17 15:38] (current) korshun
Line 8: Line 8:
 Parses s as an integer in the specified base. If base is 0, base 10 is used by default and [[:Number prefixes]] are enabled. Supports signs. Parses s as an integer in the specified base. If base is 0, base 10 is used by default and [[:Number prefixes]] are enabled. Supports signs.
  
-Returns status and result. +Returns status and parsed number. Status is one of the following:
- +
-Status is one of the following:+
   * PARSENUMBER_SUCCESS -- number successfully parsed. r2 contains the result.   * PARSENUMBER_SUCCESS -- number successfully parsed. r2 contains the result.
   * PARSENUMBER_OVERFLOW -- the number is too big to fit into a variable. r2 contains [[constants:INT_MAX]] with the sign of the number.   * PARSENUMBER_OVERFLOW -- the number is too big to fit into a variable. r2 contains [[constants:INT_MAX]] with the sign of the number.
   * PARSENUMBER_BADFORMAT -- the number failed to parse. r2 is unchanged.   * PARSENUMBER_BADFORMAT -- the number failed to parse. r2 is unchanged.
  
-See [[:Number parsing]] for features and examples.+<note tip>For simple parsing use [[atoi]].</note> 
 + 
 +===== Examples ===== 
 +<code> 
 +ParseInt("123", 0); 
 +r1 -> PARSENUMBER_SUCCESS 
 +r2 -> 123 
 + 
 +ParseInt("0", 0); 
 +r1 = PARSENUMBER_SUCCESS 
 +r2 -> 0 
 + 
 +ParseInt("999999999999", 0) 
 +r1 -> PARSENUMBER_OVERFLOW 
 +r2 -> 2147483647 
 + 
 +ParseInt("-99999999999", 0) 
 +r1 -> PARSENUMBER_OVERFLOW 
 +r2 -> -2147483647 
 + 
 +ParseInt("not a number", 0) 
 +r1 -> PARSENUMBER_BADFORMAT 
 + 
 +ParseInt("1.3", 0) -> 0 
 +r1 -> PARSENUMBER_BADFORMAT 
 + 
 +ParseInt("0xff", 0) // Hexadecimal prefix 
 +r1 -> PARSENUMBER_SUCCESS 
 +r2 -> 255 
 + 
 +ParseInt("ff", 16) // Parse in hexadecimal 
 +r1 -> PARSENUMBER_SUCCESS 
 +r2 -> 255 
 + 
 +ParseInt("0xff", 16) // 0x causes syntax error 
 +r1 -> PARSENUMBER_BADFORMAT 
 + 
 +ParseInt 
 +</code>
functions/parseint.1492432222.txt.gz · Last modified: 2017/04/17 15:30 by korshun