ACSUtils Wiki

An ACS library for ZDoom-based ports

User Tools

Site Tools


new:number_parsing

This is an old revision of the document!


Number parsing functions

Number parsing functions parse strings like “123”, “3.14” or “0xff” and return an integer or fixed-point number of the same value.

Simple number parsing

Simple number parsing functions return 0 if the input string cannot be parsed as a number, and return the minimum or maximum possible value if the input string is a number beyond value limits of ACS variables.

  • int atoi(str s) parses a string as integer and returns its value.
  • fixed atof(str s) parses a string as a fixed-point number and returns its value.

fixed numbers have a limited precision after the point. atof tries to parse fixed-point numbers to the best precision, but is biased toward 0.

Accepted formats

Number parsing functions parse the following number format:

  • Integers: <sign> <base prefix> <digits>
  • Fixed-point numbers: <sign> <base prefix> <digits> . <digits>

Sign can be +, -, or nothing (equivalent to +_.

Base prefix can be one of the following:

  • Nothing – base 10
  • 0x – base 16
  • 0o – base 8
  • 0b – base 2

Bases up to 36 are supported, using the following digits: 0123456789abcdefghijklmnopqrstuvwxyz. Digits beyond 9 are case-insensitive.

Advanced parsing functions

new/number_parsing.1518898935.txt.gz · Last modified: 2018/02/17 22:22 by korshun