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

Next revision
Previous revision
functions:parseint [2017/03/21 16:02] – created korshunfunctions:parseint [2017/04/17 15:38] (current) korshun
Line 6: Line 6:
  
 ===== Description ===== ===== Description =====
-Parses s as an integer in the specified base. If base is 0, base 10 is used by default and prefixes like ''0x'' are allowed.+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: 
 +  * 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_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.1490104953.txt.gz · Last modified: 2017/03/21 16:02 by korshun